As I read in books and in the web, in C++ we can overload the "plus" or "minus" operators with these prototypes (as member functions of a class Money
):
const Money operator +(const Money& m2) const;
const Money operator -(const Money& m2) const;
and for the assignment operator with:
const Money& operator =(const Money& m2);
Why use a reference to a Money object as a return value in the assignment operator overloading and not in the plus and minus operators?
+
or-
binary operation, what should it refer to? It makes no sense to return a reference. The operation must create a new object. – Knick