C++ Learning Manual – Operator Overloading and Friends – Operator Overloading (+, -, <<, >>)
Why Overload Operators? Imagine you have created a class <span>Complex</span> that represents complex numbers, containing real and imaginary parts. You want to use operations like <span>c1 + c2</span> directly, just like with basic types, instead of calling a function like <span>c1.add(c2)</span>. This is the purpose of operator overloading – to make custom types as convenient … Read more