On Apr 10, 10:07=A0am, Ian Collins <ian-n...@[EMAIL PROTECTED]
> wrote:
> No you completely missed the point, if you loose pass by reference, you
> make operator overloading inefficient or down right ugly.
Let met suggest the following rule: A function argument can be either
a value, a const ref, or a non const ref. Say
int f (int x);
int g (const int& x);
int h (int& x);
You call it as:
f (y);
g (y);
h (&y);
Now what about operator overloading: If you overload operator+, like a
+ b, then the expectation is that a and b are unmodified. On the other
hand, if you overload operator+=3D, like a +=3D b, you expect a to be
modified and b to be unchanged. So here is the rule: Parameters that
would not be modified if the arguments were say plain int must be
either plain value or const&. Parameters that would be modified if
they were plain ints (like the "a" in a +=3D b) must be non-const
references, and in this case the & operator (or ref keyword) is _not_
used.


|