I have a class defined in the file board.H:
class Board
{
private:
...
public:
...
};
and in another class, I want to have a member that is a pointer to a Board object:
#include "board.H"
class Bear
{
private:
Board* board;
...
public:
...
};
When I try to compile it (using g++ in linux) I get the following error:
bear.H:15: error: ISO C++ forbids declaration of `Board' with no type
bear.H:15: error: expected `;' before '*' token
What am I doing wrong?
Common problem. You probably have a
#include "bear.H"line in your “board.H” file or in a file included by “board.H”.So when you include “bear.H” into “board.H”, the “bear.H” file is processed and tries to include “board.H”, but that file is already being processed so the header guard of “bear.H” won’t include the content another time. But then “bear.H” is processed without a leading “Board” class definition.