I think there are several methods. The best is probably; you could have a virtual method named "running" in all classes. Now, if a certain game state is running, the logic would be like this:
Code:
while(state.running()) {
// Render, do events
}
The game state can now keep a local flag to indicate to the state manager that that game mode should be killed. You could even inherit that functionality similar to this:
Code:
class GameStateBaseClass {
public:
GameStateBaseClass() { _quit = false; }
virtual bool running() { return _quit; }
protected:
void doQuit() { _quit = true; }
private:
bool _quit;
};
Now any game state can simply call doQuit() to quit that game state and go to the previous one. You should never want to quit multiple states at the same time, as it's up to the state itself whether it should terminate. Eg. the game should never quit the entire program, it should go back to the main menu.
Otherwise you could have the popGameMode defined publically. The state manager probably shouldn't be a singleton, but you could pass it to the GameStateBaseClass class. Then from there you could just call _manager->popGameMode();