Operator Overloading

Nobody Understands C++: Part 8: Operator Overloading

There has been much discussion over the years about the usefulness of operator overloading in C++ as well as the ability to get it right.

In reality, it's hard to get it wrong as long as you follow the canonical forms of the operators and don't do unexpected things like overloade the + operator to perform a subtraction operation. Also, the types that your overloaded operators work with should be consistent.

Overloading && and || Operators in C++

Short answer: don't do it!

Long answer:

As the C++ example from the article on Real World Haskell Chapter 1-2 showed:

#include <iostream>
 
bool getbool(bool b)
{
  std::cout << " getbool called " << std::endl;

Syndicate content