-1

I have a file game.h which has this declaration

typedef struct Enemy {
  ...
}Enemy;

And a function

void moveEnemy(Level* l, Enemy* enemy){
  ...
}

Level is declared on levels.h, so in game.h I have:

#include "levels.h"

Everything was perfect, until I had to use Enemy in levels.h.

So, in levels.h I added:

#include "game.h"

And now I get a compilation error:

game.h:34:2: error: unknown type name ‘Level’
  Level* level;
  ^

I have include guards on both .h

I don't know why I can't have on file including another.

What can I do?

Cœur
  • 34,719
  • 24
  • 185
  • 251
Aleksandrus
  • 1,496
  • 2
  • 15
  • 29

1 Answers1

1

Just add a forward declaration, like this in game.h before the function,

typedef struct Level Level;

since it's just a pointer to Level this will do it.

Iharob Al Asimi
  • 52,066
  • 5
  • 58
  • 95