Let's say I have 2 singletons, allocated on the heap, for which no delete is ever called. Let's call them A and B. Is there any way to make sure B will be the first one to be destroyed?
I'm assuming the platform may matter on this one: Visual Studio 2005 Professional, Visual C++. Everything was built with cl
.
If they are heap allocated to normal pointers, and if delete is never called on those pointers, then they will never be destroyed, so the order of destruction is moot.
On the other hand, If you allocate them to static smart pointers, and if they are in the same translation unit, then the first one created will be the last one destroyed:
static std::auto_ptr <AType> a( new AType ); // destroyed second
static std::auto_ptr <BType> b( new BType ); // destroyed first
And lets have no nitpicking about static being deprecated :-)