O'Reilly logo

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

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 ...

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