I\'m learning C++ and I created two simple hello-world applications. In both of them I use operator overload, but here is the problem. On the first one, I can provide two argume
If you prefer that operator+
takes both operands as explicit arguments, it must be defined as a free (i.e. non-member) function:
class Complex {
friend Complex operator+(const Complex& lhs, const Complex& rhs);
}
Complex operator+(const Complex& lhs, const Complex& rhs) {
...
}
You have to use this form if the left operand is of a primitive type, or of a class that you don't control (and thus can't add a member function to).