On Wed, Apr 15, 2009 at 1:31 PM, Nat Goodspeed
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