Operator Overloading
All the operators we've seen so far have been defined by C++. That's not to say, however, that we can't overload them in our own classes just as we can with functions. Operator overloading is incredibly powerful and allows us to define our own behaviors, with our own types, for most operators available in C++. The syntax for overloading an operator is as follows:
returnType operator symbol (arguments)
Let's take a look at an example of this with a simple test class:
// Operator Overloading Example #include <iostream> #include <string> class MyClass { public: void operator + (MyClass const & other) { std::cout << "Overloaded Operator Called" << std::endl; return; } }; int main() { ...