Summary

In this hour you learned how to overload member functions of your classes. You also learned how to supply default values to functions, how to decide when to use default values, and when to overload.

Overloading class constructors enables you to create flexible classes that can be created from other objects. The initialization of objects happens at the initialization stage of construction, which is more efficient than assigning values in the body of the constructor.

The copy constructor is supplied by the compiler if you don't create your own, but it creates a shallow copy of the class. In classes in which member data includes pointers to the heap, this method must be overridden so that you allocate memory for the target object.

Get Sams Teach Yourself C++ in 24 Hours, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.