Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: C++
Expertise: Intermediate
Mar 3, 1998



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Operator overloading rules of thumb

When overloading an operator to support a user-defined type (object), it is best to adhere to the basic semantics of that built-in operator. For instance, the built-in operator ==, which does not modify any of its operands, should also be overloaded in such a way that it does not modify any of its operands (and should be declared as a const member function, as a matter of fact). On the other hand, operators such as + =, which do modify their left operand, should be overloaded in a way that reflects that, i.e., by changing their objects. Note that in many cases, the implementer
Danny Kalev
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date