24 Apr
2003
24 Apr
'03
3:56 p.m.
dick.bridges@tais.com wrote:
I don't understand C++ well enough to grok a compiler's interpretation of the code, but I seems like I'm creating an extra copy for the return. <snip>
Logically the local variable is copied to the the caller, but since the type of the returned expression matches the return type the compiler is allowed to optimise away that copy, even though the return type has a user-defined copy constructor. In this case you always return a certain named variable, so the compiler can arrange to construct it in the memory location where the caller expects the returned value. This is called the named-return-value optimisation, or NRVO.