Re: Returning by reference
To be able to do something like:Albert.
Re: Returning by reference
Hi Albert,
your assignment can be done with return by value operators, too. References are returned to modify the return value in a later expression:
Code:
// assign a + b to c, multiply c by d and store the result in c.
(c = a + b) *= d;
This cannot be done by returning by value, because it changes a temporary object only, leaving c untouched (after it has been assigned a+b), so you have to return by reference.
Regards,
Guido
Re: Returning by reference
Hi Guido,
Really? So, I was wrong!!! I thought the reference was necessary to make the last assignationThanks.
Albert.
Re: Returning by reference
Guys, thank you for the responses [:)].
Re: Returning by reference
It's also for efficiency.
Code:
Foo &operator= (const Foo& foo)
{
data = foo.data;
return *this;
}
Re: Returning by reference
Quote:
Originally Posted by AlbertGM
Hi Guido,
Really? So, I was wrong!!! I thought the reference was necessary to make the last assignation
Thanks.
Albert.
Partly true, not wrong. :)