TITLE: basic explanation of temporaries and return-by-value PROBLEM: Todd Knarr (tknarr@xmission.com) The usual method I use is: The compile allocates a temporary for the return value, then copies Temp into the temporary as part of the return. The only trick is in declaring the return to be a value not a reference, and the compiler handles the rest. RESPONSE: ell@access1.digex.net (Ell) Curious, is, or can the temporary allocated by the compiler ever be deallocated? RESPONSE: clamage@Eng.Sun.COM (Steve Clamage), 7 Feb 96 When the compiler creates a temporary object, it is responsible for destroying it (via its destructor) at the proper time. The temps are normally on the stack (or in a register for simple types), so it is not a new/delete issue, but only a construct/destroy issue. There is no conceptual difference between returning an int by value from a routine, and returning a class object by value. The value must be created somewhere, the value is copied to its destination, and the space used for that value is reclaimed. In some cases the value can be created directly in its destination, avoiding an extra copy. It's up to the compiler whether an int value is returned on the stack, in a register, or by some other method. The same is true for values of class type. If an extra copy is needed, it is up to the compiler to create and destroy it.