Skip to main content
gamedev.net
🔒 Locked

#include madness

Started by SFA 1 reply 400+ views
Original Post
SFA
SFA
I'm writing a rather large project in C++. I have many classes (lets say 20) and they all have corresponding header files. I have one header file called main.h which declares global classes. I have a class called 'creatures' which contains 4 limb subclasses. Now what I want to do is declare my creatures globally (so that they can transfer data to eachother). But when I add creatures.h to the main.h file (so I can declare them as global variables), the compiler spits out this error :
Quote:
Creature.h(17) : error C2143: syntax error : missing ';' before '*' Creature.h(17) : error C2501: 'Limb' : missing storage-class or type specifiers Creature.h(17) : error C2501: 'leg' : missing storage-class or type specifiers
If I remove #include Creatures.h from main.h, it compiles perfectly. So my question is why does adding this header file cause the compiler to not know what a 'limb' is? Especially when you consider that limb.h is actually included in main.h itself, and creature.h. Any help would be great. I've tried everything I can think of all day, but to no avail.
http://www.voodoo-magic.co.uk
The Rug
The Rug
Have you missed a semo-colon off somewhere, ie. the end of a class definition, struct, etc.?
the rug - funpowered.com
ApochPiQ
ApochPiQ
Order will make a difference; what order are limb.h, creature.h, and main.h included in main.cpp?

Also, it's usually considered a good idea to put dependencies in your header files directly rather than relying on the final .cpp including them all for you. For example, since Creature references Limb objects, #include "limb.h" at the top of creature.h, so that anyone who wants to use a Creature doesn't have to know all of the other headers that are required. Just #include "creature.h" and you're all set. The C++ standard library works this way (e.g. #include and notice how also implicitly gets included).

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.