Possible Duplicate:
Guaranteed lifetime of temporary in C++?
Lifetime of temporaries
I have a quick question regarding the lifespan of a temporary object, when returned from an overloaded operator+
method. For example, if the expression...
a = b + c + d + e
...is evaluated by overloaded operator+
methods which return temporary objects, is the scope of the temporary returned by the sub-expression b + c
that of the entire expression?
As g++ appears to hold onto all temporaries whilst the entire expression is within scope, references to these values may be held for delayed evaluation during the a =
assignment.
Could somebody please confirm whether or not this behaviour is guaranteed for all C++ implementations?