On Fri, Oct 20, 2006 at 06:08:29AM -0400, Andre Pang wrote: > > You need to return an actual std::string, not a reference to one (the > latter is invalid C++). The normal idiom is to mark the returned string > as a const reference in the calling function:
And Peter Miller says: > And then there are optimisations: your example begs for the optimiser to > notice that it is possible for s to be the place the return value will > be copied to anyway, and not within the function's stack frame at all. As I understand it, the idiom Andre mentions(using a const ref on the lhs) makes it pretty much guaranteed you'll get this optimisation in modern compilers. You can check (for your own classes) by having the constructor and destructor log their invokations. Matt _______________________________________________ coders mailing list [email protected] http://lists.slug.org.au/listinfo/coders
