I think you misinterpreted my post :) Allow me to elaborate what I mean with this example:
1 2 3 4 5
|
class Cake
{
public:
Cake &operator + ( Cake & );
};
|
I've added the & operator before the
operator keyword. This will return a reference to
*this. Now, if you want to return a new instance of
Cake, you would omit the & operator.
Within the parameter list, I added another & operator. This now means that the operator takes a reference to an instantiation of
Cake. If I omitted the & operator, a copy of the passed instantiation of
Cake would be made and the changes would not take effect.
If you placed the
const qualifier after the parameter list, you would restrict the operator from making changes to the data members.
You should also note that non-bitwise operators (such as +, -, /, etc) should not modify the neither left-hand or right-hand operand, but return a copy of the two operands added together. Only bitwise operators should modify the operands.
Wazzak