Well, that's why I would avoid at all costs placing side effects into my operator overloads. One can, for example, define addition so that it modifies the values of both variables added! For example:DiGuru said:Yes. But I rather type a bit more than having to guess about how my code might be executed.
Code:
int operator +(int &a, int &b)
{
a++;
b--;
return a+b;
}
For example, when I was browsing around the net for increment/decrement overloads, I even noticed that one example used "void" as the return value: this would probably be the best thing to do, as it would prevent the use of the operator in a statement where its result is undefined.