//GState.h//
#include "GStateFlow.h"
class GStateFlow;
class GState
{
  public:
  virtual void NextState(GStateFlow* State)=0;
};
class LoaderStateUNKNOWN:public GState
{
  public:
  virtual void NextState(GStateFlow* State)
  {
    ShowMessage("State is UNKNOWN,turn to Reset");
    State->SetState(new LoaderStateRESET());
  }
};
class LoaderStateRESET:public GState
{
  public:
  virtual void NextState(GStateFlow* State)
  {
    ShowMessage("State is Reset.");
  }
};

//GStateFlow.h
#include "GState.h"
class GState;
class GStateFlow
{
  public:
  GStateFlow(){this->CurrentState = new LoaderStateUNKNOWN();}
  ~GStateFlow(){delete CurrentState;}
  void SetState(GState* State){CurrentState=State;}
  void NextState(){CurrentState->NextState(this);}
  protected:
  GState* CurrentState;
};