I would like to write a simple game using SDL 2.0, and its structure looks kind of like this:
- class Engine, which will initialize SDL(SDL.Init() ) in its constructor, call SDL_Quit() in destructor, and contain instances of Window and Texture
- class Texture - wrapper class for SDL_Texture* . Creating texture when created, destroying texture in destructor
- class Window - wrapper class for SDL_Window, creating SDL_Window* and SDL_Renderer* at beggining, deleting in destructor.
Now, from what I know, SDL_Quit() unloads dll, closes all subsystems, etc. If I understand correctly, then if I call SDL_Quit(), calling SDL_DestroyWindow(), SDL_DestroyRenderer() and SDL_DestroyTexture() may have no effect or cause bug, because systems have been unloaded as well as dll.
Therefore, I would like Texture and Window inside Engine to be destroyed in the beggining of Engine's destructor, before SDL_Quit() is called.
When I tried simulating it on a simple class example, I got simple LIFO response:
ClassOne object initialized
ClassTwo object initialized
Aggregate object initialized
Aggregate object destroyed
ClassTwo object destroyed
ClassOne object destroyed
And it isn't what I want. I managed to get solution to my problem using pointers and dynamic memory allocation. I simply create them using operator new in Aggregate's constructor, and destroy them, using operator delete in destructor.
But, is there other way to do it, not involving pointers? Thanks in advance.