Summary

In this hour you learned about operator overloading.

The copy constructor and operator= are supplied by the compiler if you don't create your own, but they create a shallow copy of the class. In classes in which member data includes pointers to the heap, methods must be overridden so that you allocate memory for the target object.

Almost all C++ operators can be overloaded, although you want to be cautious not to create operators whose use is counterintuitive. You cannot change the arity of operators, nor can you invent new operators.

The this pointer refers to the current object and is an invisible parameter to all member functions. The dereferenced this pointer is often returned by overloaded operators.

Conversion operators enable you ...

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.