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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.