0

I have a class structure like this:

Entity
Creatures and Tiles are Entities
Players and Enemies are Creatures

My problem comes in a header file that includes both enemy.h and tiles.h. I'm not really sure what the problem is, but it will only compile properly if I don't include one of the headers. This is a stripped down version of what I have.

#include "enemy.h"
#include "tiles.h"

class foo
{
  public:
    list<Entity>* GetTiles();
    list<Entity>* GetEnemies();
  private:
    list<Entity>* tilesList();
    list<Entity>* enemiesList();
}

Before I threw in enemy.h and the enemy functions, it compiled properly. enemy.h includes creature.h which includes entity.h. tiles.h includes entity.h

I'm really not all that familiar on how #include really works, but it's obvious that it's the problem. How can I fix this?

Sam
  • 7,252
  • 16
  • 46
  • 65
barwin
  • 13
  • 3
  • You probably need code guards in your header files to prevent duplicates since presumably both enemy.h and tiles.h eventually include entity.h – YoungJohn May 13 '14 at 16:34
  • I have guards in every header file. I was always under the impression that guards were there to prevent errors like mine. – barwin May 13 '14 at 16:35
  • code guards do NOT resolve circular dependencies, but I linked the proper question, that has an extensive answer – Mahrgell May 13 '14 at 16:38

1 Answers1

-1

Why don't you post compiler output? I'm pretty sure that's forgotten include guard as guys mentioned in comments - be sure to check out not only files that you talk about, but every include header that you include in them - maybe there something like "utils.h" missing guards being included by other headers.

bigblackdot
  • 138
  • 1
  • 9
  • as mentioned in the comment on the question, includeguards do not protect against circular dependencies... Please stop spreading misinformation. – Mahrgell May 13 '14 at 17:02
  • Why on earth you're so sure barwin facing circular dependency issue? I can't see any clue to be sure of it in question text. Thanks for minus, btw. – bigblackdot May 13 '14 at 17:12