std::unique_ptr does not control when the destructor is called. Instead, he announces that he determines in which order he is destroyed.
Members of a class are constructed in the order in which they are declared in the body of the class, and are destroyed in the reverse order of that order. Therefore, in your case, when a App displayManager is built, the renderer is built first, and then the renderer is built. When the App instance is destroyed, then the renderer destroyed first, and then the displayManager destroyed.
Also note that in
App::App() { displayManager = std::unique_ptr<DisplayManager>(new DisplayManager); renderer = std::unique_ptr<Renderer>(new Renderer); }
You are doing the default assignment to unique_ptr s. You need to use a member initialization list like
App::App(): displayManager(new DisplayManager), renderer(new Renderer) {}
If you do not want to construct pointers by default, then assign them.
source share