Re: Friend operators don't work where class member operators do.
cesar tejeda wrote:
[...]
But, why should the operations that use temporaries be declared const ?
They are going to be destroyed afterwards, so, why minding about if
they change values?
You're looking at it from the wrong side. Presumably, if you do
modify them, it's for a purpose. And if you immediately destroy
the object, you loose the modification (and the purpose).
Historically (some twenty years ago), C++ did allow binding a
temporary to a non-const reference (and many compilers still
allow it today, as a non-conformant extension). It was found,
however, to be somewhat error prone, in cases like e.g.:
void
incr( int& i )
{
++ i ; // Obviously something more complex in real
// code.
}
void
f()
{
unsigned x = 0 ;
incr( x ) ;
}
In this case, the temporary is the result of an implicit
conversion, and the author is very surprised that the call to
incr doesn't modify x.
--
James Kanze (Gabi Software) email: james.kanze@gmail.com
Conseils en informatique orient?e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S?mard, 78210 St.-Cyr-l'?cole, France, +33 (0)1 30 23 00 34
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]