problem in compiling the c++ code

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'
 
A

Attila Feher

Peter said:
You have to forward declare TurnStyleContextFSM.

And use a standard iostream header without the .h, because then comes the
string inclusion without the .h and the wondering while prestandard
iostreams and standard string does not owrk together. :-(
 
C

Chris Theis

ravinder said:
#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)

At this point of compilation the class TurnStyleContextFSM has not yet been
defined. However, you can resolve this problem by forward declaring it.

[SNIP]
I am compiling the above code in VC++ windows environment, i am getting the compilation errors like:
error C2061: syntax error : identifier 'TurnStyleContextFSM'

HTH
Chris
 
J

Jai Kumar

Peter Gerell said:
You have to forward declare TurnStyleContextFSM.

Even if you forward declared TurnStyleContextFSM and made minor
corrections to the code (<iostream.h> to <iostream>, void main() to
int main(), Pass to Pass(),etc) it is still very unlikely that the
code will compile. Have you tried it?

Jai Kumar.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,160
Messages
2,570,889
Members
47,420
Latest member
ZitaVos505

Latest Threads

Top