how to avoid header file duplication?
<p>Hi guys in my program i got two header files named "invader.h" and "game.h", in game.h i include invader.h and because i wanna pass a pointer to current game instance to an invader instance. i also include game.h in invader.h but i got compile error.if i remove game.h from invader.h it works fine. i already add include guard in each header file. based on what i've found so far i add a forward declaration of game class in invader.h because what i need is a pointer to game instance in invader.h, but when i wanna call a function of game in invader.cpp, it says pointer to incomplete class type is not allowed. what should i do to solve this problem?</p>

<p>Game.h</p>

<pre><code>#ifndef GAME_H
#define GAME_H
#include "Tank.h"
#include "Invader.h"
#include "Block.h"
#include "Bullet.h"

class Game
{
private:
Tank tank;
Invader invaders[11][5];
Block blocks[4];
bool logicRequiredThisLoop = false;
public:
Game();
void initEntities();
Tank* getTank(){return &amp;tank;};
Invader* getInvaders(){return &amp;invaders[0][0];};
Block* getBlocks(){return &amp;blocks[0];};
void updateLogic();
};
#endif
</code></pre>

<p>Invader.h</p>

<pre><code>#ifndef INVADER_H
#define INVADER_H
#include "Entity.h"
class Game; //forward declaration of class Game
class Invader: public Entity
{
private:
Game* game;
public:
Invader(){};
Invader(Game*,char*,int,int,int,int,int,int);
void move(long delta);
void doLogic();
};
#endif
</code></pre>

<p>Invader.cpp</p>

<pre><code>#include "Invader.h"
Invader::Invader(Game* game,char* sprite,int x,int y,int dx,int dy,int width,int height):Entity(sprite,x,y,dx,dy,width,height)
{
this-&gt;game = game;
}

void Invader::move(long delta)
{
if ((dx&lt;0)&amp;&amp;(x&lt;=10))
{
    game-&gt;updateLogic();
}
if ((dx&gt;0)&amp;&amp;(x&gt;=390))
{
    dx = -dx;
    y -= dy;
}

x+=dx;
}
</code></pre>

<p>in Invader.cpp when I try to call updateLogic() which is a member function of Game class, an error occurs saying the pointer to an incomplete class is not allowed</p>

<p>Actually to be simple the most basic thing I want to know here is: in my code Game class has an invader type member variable, so how can I call member functions of Game class in invader class?li,e I said if I include Invader.h in Game.h and include Gameh.h in Invader.h an compile error occurs.</p>

<p>this is what in get when I include Game.h in Invader.h:</p>

<pre><code>1&gt;ClCompile:
1&gt;  Invader.cpp
1&gt;c:\users\tony\documents\info3220\spaceinvader\spaceinvader\basicwogl\game.h(13): error C2146: syntax error : missing ';' before identifier 'invaders'
1&gt;c:\users\tony\documents\info3220\spaceinvader\spaceinvader\basicwogl\game.h(13): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1&gt;c:\users\tony\documents\info3220\spaceinvader\spaceinvader\basicwogl\game.h(13): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1&gt;c:\users\tony\documents\info3220\spaceinvader\spaceinvader\basicwogl\game.h(21): error C2143: syntax error : missing ';' before '*'
1&gt;c:\users\tony\documents\info3220\spaceinvader\spaceinvader\basicwogl\game.h(21): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1&gt;c:\users\tony\documents\info3220\spaceinvader\spaceinvader\basicwogl\game.h(21): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1&gt;c:\users\tony\documents\info3220\spaceinvader\spaceinvader\basicwogl\game.h(21): warning C4183: 'getInvaders': missing return type; assumed to be a member function returning 'int'
1&gt;c:\users\tony\documents\info3220\spaceinvader\spaceinvader\basicwogl\game.h(21): error C2065: 'invaders' : undeclared identifier
</code></pre>
