R
ravinder
#include <iostream.h>
/* This class captures all the events as virtual functions. This class
is a base class, and not one of the actual states of the FSM. */
class TurnStyleState
{
public:
virtual void Coin(TurnStyleContextFSM *) {};
virtual void Pass(TurnStyleContextFSM *) {};
};
class LockedTurnStyleState : public TurnStyleState
{
public:
virtual void Coin(TurnStyleContextFSM* c)
{c->SetState(TurnStyleContextFSM::unLocked); c->Unlock();}
virtual void Pass(TurnStyleContextFSM* c)
{c->Alarm();}
};
class UnlockedTurnStyleState : public TurnStyleState
{
public:
virtual void Coin(TurnStyleContextFSM* c)
{c->ThankYou();}
virtual void Pass(TurnStyleContextFSM* c)
{c->SetState(TurnStyleContextFSM::Locked); c->Lock();}
};
class TurnStyleContext
{
public:
void Lock();
void Unlock();
void Alarm();
void ThankYou();
};
class TurnStyleContextFSM : public TurnStyleContext
{
private:
TurnStyleState* itsState;
public:
static UnlockedTurnStyleState Unlocked;
static LockedTurnStyleState Locked;
void Coin() {itsState.Coin(this);}
void Pass() {itsState.Pass(this);}
TurnStyleState* GetState() {return itsState;}
void SetState(TurnStyleState* s) {itsState = s;}
};
void main()
{
TurnStyleContextFSM fsm;
fsm.SetState(TurnStyleContextFSM::Locked);
fsm.Lock();
for(;
{
fsm.Coin();
fsm.Pass;
}
}
I am compiling the above code in VC++ windows environment, i am getting the compilation errors like:
error C2061: syntax error : identifier 'TurnStyleContextFSM'
/* This class captures all the events as virtual functions. This class
is a base class, and not one of the actual states of the FSM. */
class TurnStyleState
{
public:
virtual void Coin(TurnStyleContextFSM *) {};
virtual void Pass(TurnStyleContextFSM *) {};
};
class LockedTurnStyleState : public TurnStyleState
{
public:
virtual void Coin(TurnStyleContextFSM* c)
{c->SetState(TurnStyleContextFSM::unLocked); c->Unlock();}
virtual void Pass(TurnStyleContextFSM* c)
{c->Alarm();}
};
class UnlockedTurnStyleState : public TurnStyleState
{
public:
virtual void Coin(TurnStyleContextFSM* c)
{c->ThankYou();}
virtual void Pass(TurnStyleContextFSM* c)
{c->SetState(TurnStyleContextFSM::Locked); c->Lock();}
};
class TurnStyleContext
{
public:
void Lock();
void Unlock();
void Alarm();
void ThankYou();
};
class TurnStyleContextFSM : public TurnStyleContext
{
private:
TurnStyleState* itsState;
public:
static UnlockedTurnStyleState Unlocked;
static LockedTurnStyleState Locked;
void Coin() {itsState.Coin(this);}
void Pass() {itsState.Pass(this);}
TurnStyleState* GetState() {return itsState;}
void SetState(TurnStyleState* s) {itsState = s;}
};
void main()
{
TurnStyleContextFSM fsm;
fsm.SetState(TurnStyleContextFSM::Locked);
fsm.Lock();
for(;
{
fsm.Coin();
fsm.Pass;
}
}
I am compiling the above code in VC++ windows environment, i am getting the compilation errors like:
error C2061: syntax error : identifier 'TurnStyleContextFSM'