I have a std::stack which has some pointers inside:
std::stack<State*> m_states;
When I initialize my program, I call new to push an item onto the stack (it must be a pointer because I will use polymorphic types).
Is this the correct way of deleting with all the stuff?
Here is where I call new (GameState and MenuStatesare classes inherited fromState`):
m_states.push(new GameState());
m_states.push(new MenuState());
And this is what I have in the destructor of the whole App class:
while (!m_states.empty())
{
delete m_states.top(); // (*)
m_states.pop();
}
Should I only call (*), or do I need to pop() as well?
unique_ptrand not have to deal with cleanup at all.