I am currently working on a two-dimensional game engine, and I read about auto_ptr and how you should never put them in standard containers.
My engine has this structure:
StateManager - has many → states.
States are created and distributed mainly outside the engine. I want the engine to keep a list / vector of all states, so I can switch between them on command.
For instance:
SomeState *test = new SomeState();
StateManager->registerState(test);
Since states die if and only if the application dies, can I use this approach?
std::auto_ptr<SomeState> test(new SomeState());
StateManager->registerState(test.get());
// Inside StateManager State * activeState; // State manager then maintains a vector std :: vector <State *> stateList; // and upon registerState it adds the pointer to the vector void registerState (State * state) {stateList.push_back (test); }
StateManager , . , activeState, , stateList.
?