Boost logo

Boost Users :

Subject: Re: [Boost-users] Covariant return type, method hiding, and shared_ptr advice
From: Dominique Devienne (ddevienne_at_[hidden])
Date: 2009-04-15 15:06:00


On Wed, Apr 15, 2009 at 1:31 PM, Nat Goodspeed <nat_at_[hidden]> wrote:
> Dominique Devienne wrote:
>> PS: is returning a const shared_ptr<T>& is better/worse than a copy?
>
> My rule of thumb is: pass by const reference, return by value.
>
> I keep having to change other people's code when a method is declared to
> return const std::string&, and suddenly I need to return a string expression
> rather than a reference to a data member. Even more irksome is when that
> signature is declared on a virtual method. Then -- to change the computation
> of one return value in one override -- I must run around changing *every*
> signature.

We do pass by const&, but too often also return by const&.
Your point about it being especially wrong for virtuals is a good one.
I'll try to remember it.

Thanks, --DD


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net