The virtual function approach is the one I''ve found to be the best. You have a base class IAppState:
class IAppState{ public: virtual bool Enter()=0; //tell the state to start up virtual void Draw()=0; virtual void Update(float timeStep)=0; virtual void Leave()=0; //tell the state to shut down};
You make the functions ''pure virtual'' (virtual with =0 on the end) to force derived classes to implement them, so that way you don''t forget to provide a Leave() function or whatever.
Then you just derive from it, and have a singleton AppStateManager somewhere, which contains an IAppState pointer to the current state, and has a SwitchState() function which calls Enter() and Leave() on the appropriate states.
Superpig
- saving pigs from untimely fates, and when he''s not doing that, runs The Binary Refinery.