#ifndef PLAYER_H
#define PLAYER_H
/*************** Forward Declerations ****************/
class Turn;
class Current;
class Wait;
/*****************************************************/
/************************************ Player Class *****************************************/
class Player
{
public:
Player();
void endTurn();
void setTurn(Turn*);
bool isTurn() const;
virtual ~Player();
private:
Turn* turn;
};
/*******************************************************************************************/
/************************************** State Class ****************************************/
class Turn
{
public:
Turn();
virtualbool isTurn() const = 0;
virtualvoid end(Player*) = 0;
};
class Current : public Turn
{
public:
virtualbool isTurn() const
{
returntrue;
}
virtualvoid end(Player* p)
{
p->setTurn(new Wait());
deletethis;
}
};
class Wait : public Turn
{
public:
virtualbool isTurn() const
{
returnfalse;
}
virtualvoid end(Player* p)
{
p->setTurn(new Current());
deletethis;
}
};
/*******************************************************************************************/
#endif
These are my errors:
In member function `virtual void Current::end(Player*)':|
Player.h|46|error: invalid use of undefined type `struct Wait'|
error: forward declaration of `struct Wait'|
why does it think my forward decleration is a struct? i can't see anything wrong with my code. Please help.
It doesn't matter. The line of code won't compile unless the compiler can see the complete
body of class Wait, which means you have to #include it (and remove the forward declaration)
or else move the implementation of Current::end() to the .cpp file and #include the header
for Wait there.
there's no difference between class and struct. The problem is that you are calling Wait constructor before it ( the constructor ) is declared ( implicitly in class Wait )
You should move Turn::end on another file to solve this