O'Reilly logo

Sams Teach Yourself C++ in 24 Hours, Third Edition by Jesse Liberty

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required