Is it possible to remove a dynamically allocated class using a function inside that class?
I am writing a state manager for the game. I have most of the logic for how I want to do this. I want the states to be classes handled on the stack in the StateManager class. Each state will have pause functions and the stack will be an STL stack.
When a state is executed with what it needs to do (for example: from the pause screen, the user presses back to play), it needs to be removed from the stack and removed. My current logic (which I was unfortunately unable to verify, unfortunately):
The state is completing its work. In its update function, when it detects that it is done, it will call a function to clear the state. This function will take care of any loose ends that need to be anchored (if any), call pop from the state manager stack and pop yourself.
I ask: can I remove a class from myself?
source to share
See C ++ - FAQ-lite: Is it legal (and moral) for a member function to saydelete this?
As long as you are careful, it is okay for the subject to commit suicide (delete that).
source to share