I am making a global singleton that controls my application and I want the subsystems to startup and shutdown in a specific order.
class App
{
public:
App();
~App();
void start();
void run();
void shutdown();
private:
std::unique_ptr<DisplayManager> displayManager;
std::unique_ptr<Renderer> renderer;
};
The constructor creates the pointers in the correct order
App::App()
{
displayManager = std::unique_ptr<DisplayManager>(new DisplayManager);
renderer = std::unique_ptr<Renderer>(new Renderer);
}
and I want the unique_ptrs to be deallocated in the reverse order. Does std::unique_ptr have a guarantee that the memory will be deallocated in this order?
I thought about making all of the managers global singletons, but felt this way would be better if I could make it work.
EDIT: It has been brought to my attention that the actual problem is the order that an instance variables members get destructed. In that case is there a guaranteed order for that?