From 8845359773261890773
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,bda3b729e5d0c564
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 1993-04-04 12:09:53 PST
Path: gmd.de!Germany.EU.net!news.dfn.de!darwin.sura.net!zaphod.mps.ohio-state.edu!uwm.edu!linac!att!att!allegra!alice!bs
From: bs@alice.att.com (Bjarne Stroustrup)
Newsgroups: comp.std.c++
Subject: Re: Guaranteed order of destruction for auto objects?
Summary: yes
Message-ID: <25207@alice.att.com>
Date: 4 Apr 93 18:24:06 GMT
Article-I.D.: alice.25207
References: <C4vJy3.5FH@finnbogi.ocs.com>
Organization: AT&T Bell Laboratories, Murray Hill NJ
Lines: 21



Fobi@finnbogi.ocs.com (Obi Thomas @ Online Computer Systems, Inc.) writes 

 > Does the standard guarantee the order of calling destructors for automatic
 > objects? Suppose I have a situation like this:
 > 
 > void FooBar()
 > {
 >     Foo a;
 >     Bar b(a);
 >     ...
 > }
 > 
 > "b" stores a reference to "a" in its constructor and then needs to use the
 > reference in its destructor. Is this safe? Am I guaranteed that "a" is
 > destroyed after "b" so that the reference to "a" is valid in Bar::~Bar()?

There isn't an official standard yet, of course, but `yes' you can rely on
the order of destruction of named local objects to be the reverse of their
order of construction.


