Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: #include Puzzle  (Read 3162 times)

0 Members and 1 Guest are viewing this topic.

Dark Goomba

  • Newbie
  • *
  • Posts: 9
    • View Profile
#include Puzzle
« 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.
Goombas are mushrooms.

greenk

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: #include Puzzle
« Reply #1 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.
« Last Edit: June 21, 2014, 07:44:36 am by bottles »

AlexAUT

  • Sr. Member
  • ****
  • Posts: 396
    • View Profile
Re: #include Puzzle
« Reply #2 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

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: #include Puzzle
« Reply #3 on: June 21, 2014, 09:48:43 am »
Make sure each header file is self contained and has correct include guards.

Dark Goomba

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: #include Puzzle
« Reply #4 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.  :)
« Last Edit: June 22, 2014, 03:57:42 am by Dark Goomba »
Goombas are mushrooms.

 

anything