logo       

Re: Order of Object destruction: msg#00206

gcc.help

Subject: Re: Order of Object destruction

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




<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise