forward decleration error

this is my header file:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#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();

        virtual bool isTurn() const = 0;
        virtual void end(Player*) = 0;
};

class Current : public Turn
{
    public:
        virtual bool isTurn() const
        {
            return true;
        }
        virtual void end(Player* p)
        {
            p->setTurn(new Wait());
            delete this;
        }
};

class Wait : public Turn
{
    public:
        virtual bool isTurn() const
        {
            return false;
        }
        virtual void end(Player* p)
        {
            p->setTurn(new Current());
            delete this;
        }
};
/*******************************************************************************************/


#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.
Last edited on
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.

BTW, "delete this" is rarely a good thing.
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
Topic archived. No new replies allowed.