Topic: destr. seq. inv. of constr. seq. ?
Author: andys@thone.demon.co.uk (Andy Sawyer)
Date: Thu, 2 Feb 1995 23:48:31 +0000 Raw View
In article <3gc2g7$214@news.uni-c.dk>
mojemj@unidhp.uni-c.dk "Mogens Jensen" writes:
>
> Hi there!
>
> Some time ago I read in this group that the standard does not guarantee
> that objects are destroyed in the reverse order they are constructed (!)
>
> When using resource handling classes, which is a major issue in C++ IMHO,
> it can be vital: some resources has to be deallocated in the reverse
> order they were allocated.
>
If this is causing you a problem, you can try something like this:
void func( void )
{
Resource R;
{
SomeOther S( &R ); // S requires R for initialisation
{
EvenMore E( S ); // and E requires S
} // E's destructor called hereabouts
} // S's destructor called hereabouts
} // R's destructor called hereabous
It's not pretty, but it should work.
Regards,
Andy
--
* Andy Sawyer ** e-mail:andys@thone.demon.co.uk ** Compu$erve:100432,1713 **
The opinions expressed above are my own, but you are granted the right to
use and freely distribute them. I accept no responsibility for any injury,
harm or damage arising from their use. -- The Management.