Order of constructor/destructor invocation

Christian Tanzer tanzer at swing.co.at
Thu Mar 7 12:48:13 EST 2002


Björn Lindberg <d95-bli.no at spam.nada.kth.se> wrote:

> > void a_function ()
> > {
> >         sentry1 s1, s2;
> >         ...
> > }
> >
> > ? Will s1 be destructed before s2 by all compilers? Guess, I never
> > cared about that because I tend to use multiple declarations myself.
>
> The destruction order is always opposite of the construction order.

Agreed. I relied on that.

> In this example s1 will be constructed first followed by s2.

And here I am wary. Does the standard prescribe this? For normal
expressions at least, you can't rely on evaluation order. But then, in
comma separated expressions you can. So maybe this is safe after all.

Don't-really-want-to-refresh-my-C++-ly yr's,

-- 
Christian Tanzer                                         tanzer at swing.co.at
Glasauergasse 32                                       Tel: +43 1 876 62 36
A-1130 Vienna, Austria                                 Fax: +43 1 877 66 92





More information about the Python-list mailing list