Order of Object destruction
Eljay Love-Jensen
eljay@adobe.com
Fri May 23 12:12:00 GMT 2003
Hi Neophytos,
Yes, the order of destruction is specified, due in no small part to the
lifespan of a temporary being well-defined.
Effectively, the temporary object lives until the end-of-statement semicolon.
As I understand it (I've never needed to tried this), if there were an
alias to it, it would live until the end of the extant of alias. For example:
A a;
A& b = foo(a);
// a and b are live.
cout << a.y << endl;
cout << b.y << endl; // Okay.
Before the standard's committee nailed the issue, compiler vendors were
inconsistent when the temporary object was destructed. Which lead to all
sorts of non-portable code and frustrated programmers.
--Eljay
More information about the Gcc-help
mailing list