Lieven de Cock - 2005-02-27

Logged In: YES
user_id=602705

I want to remark, that syntactically, the program also has a
minor mistake :
the mentioned operator should be
operator+ (no space in between the word and the + sign).
That is the correct name !

I am surprised the compiler did not complain, since you
can't write either :
void my function(int i);
I just checked and indeed the compiler goes ahead with the
operator (with rewrite of &X to X&), and does give an error
on the "my funcion". So the compiler did some corrective
things, should devcpp??? Maybe yes, but maybe no.
I checked your statement by replacing the + by a *, and then
devcpp does show it as you claim. So in that case I'll
support your report, decpp should do it also then for the +.

I'd like to also add that it is good practice to have the
operator+ not being a member method ( x + 1, yes, but : 1 +
x ???)!!
It should be :
const X operator+(cont X& lhs, const T& rhs);

where you should implement it as follows :
{
X ret(lhs)
lhs += rhs;
return ret;
}

and you implement the operator+= as a member method

X& X::operator+=(const T& other)
{
n += T.n
return *this;
}

Don't just take my word for it, take a look at the excellent
book
Exceptional C++ by Herb Sutter.
ISBN : 0-201-61562-2

And read Item20:Class Mechanics, page 69.

kind regards,
Lieven