Rolf Magnus :
> Bo Yang wrote:
>
>>> By reference is usually returned
>>> (1) *this (typically in overloaded operator=) or
>>> (2) some class member instance or
>>> (3) instance stored in some container
>>>
>>> The main rule is "Instance must not be local variable of function,
>>> which returns reference to it.
>> And when I implement a '-' operator in a class,
>> I must to do
>>
>> Test & operator -( Test & right ) ;
>
> Usually, you let that operator take a const reference as argument and return
> an object instead of a reference.
I have take a look at the FAQ and found
the return type is usually a value but a reference.
I understand the principle, return by reference only
if the object you return is all at your control.
Thank you!
>
>> How to implement this function then ?
>> I must to new a Test in this function , mustn't I ?
>
> No. Well, you can, but shouldn't. You simply don't return by reference.
>
|