Order of Object destruction

LLeweLLyn Reese llewelly@lifesupport.shutdown.com
Sat May 24 13:15:00 GMT 2003


Eljay Love-Jensen <eljay@adobe.com> writes:

> Hi Neophytos,
> 
>  >When the call foo(a) is made the copy constructor is called and
> makes a new object "z".  This object "z" is supposed to be desposed
> off when it goes out of scope.
> 
> Correct.  And it does.  Temporary object "z" goes out of scope at the
> caller's semi-colon.
> 
> Returned object "b" also goes out of scope at the caller's semi-colon.
> 
>  >I was asking which was supposed to be desposed of first "z" or "b"?
> 
> I think it is up to the discretion of the compiler's vendor whether
> it's a LIFO object destruction at the semi-colon, or FIFO object
> destruction.

I can't find anything in the standard which requires either of
    these. Until someone does, you should probably assume any order is
    possible. (though C++ doesn't allow interleaving of distinct
    functions, so that isn't possible.)



More information about the Gcc-help mailing list