Operator Overloading Can Be Dangerous

Operator overloading is one of the most overused and misused capabilities of C++. It is your responsibility to make sure that you do not misuse an operator symbol so that another programmer's intuitive understanding of what the operator means is violated. For instance, do not overload + to subtract, or reimplement ! to make a number negative. Also, you should clearly explain what any overloaded operator does by providing a comment where the operator is declared in the header file.

In general, your code is much more readable when you use conventional member functions with meaningful names rather than overloaded operators.

Overloading the << Operator

anExternalInterface might be somewhat easier to use if it ...

Get SAMS Teach Yourself C++ in 10 Minutes SECOND 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.