SFML community forums

Help => General => Topic started by: Dark Goomba on June 21, 2014, 07:07:42 am

Title: #include Puzzle
Post by: Dark Goomba on June 21, 2014, 07:07:42 am
Hi everyone. I am working on a game that has a lot of files. The problem is that I don't think that I am including the header files in the right sequence, so some of the classes are undefined. The files are Battlefield.h, Creature.h, Enemy.h, Button.h. I've spent hours trying to code it so:

Battlefield.h  has Creature.h, Enemy.h, and Button.h defined.
Creature.h    has Enemy.h and Battlefield.h defined.
Enemy.h       has Creature.h and Battlefield.h defined.
Button.h       has Creature.h and Battlefield.h defined.

Thanks in advance.
Title: Re: #include Puzzle
Post by: greenk on June 21, 2014, 07:43:04 am
The order of #include statements shouldn't matter and are a sign you are doing something wrong somewhere. Could you edit the OP with the contents of your header files? That might make the issue clearer, although I suspect this:
http://en.wikipedia.org/wiki/Forward_declaration
might be helpful reading.
Title: Re: #include Puzzle
Post by: AlexAUT on June 21, 2014, 09:03:37 am
As bottles already mentioned you should have a look at forward declaration, because you can't include a header which already includes this header... The compiler will give strange errors when you do this like i.e. this class is not defined....


AlexAUT
Title: Re: #include Puzzle
Post by: Jesper Juhl on June 21, 2014, 09:48:43 am
Make sure each header file is self contained and has correct include guards.
Title: Re: #include Puzzle
Post by: Dark Goomba on June 22, 2014, 03:51:28 am
Yes, all of the guard tags are properly used and the header files are self contained. I am just unsure which files should include what.

Edit: I tried the forward declarations and IT WORKED! Thanks everyone.  :)