Archived

This topic is now archived and is closed to further replies.

The Canary Man

Header Inclusion problems

Recommended Posts

Fruny    1658
You have a recursive dependency problem : CWrestler needs CTeam and vice-versa.

wrestler.h includes team.h which tries to include wrestler.h to get the definition of CWrestler, but the include guard prevents it. So team.h never gets the definition of CWrestler.

You should restructure your classes to use references, or pointers to the other class instead of an actual instance of the object. When you have an actual instance, the compiler needs to know the size of the data structure, and thus needs the complete definition. When you have a reference or a pointer, it justs takes into account the space for the 32-bit pointer.

Therefore, you can just tell it that there is a class named CTeam or CWrestler (by writing ''class CTeam;'' or ''class CWrestler;'') and not include the whole definition.

It is usually considered bad form to #include headers in headers, unless you REALLY cannot do without them. Just declare the needed symbols.

Share this post


Link to post
Share on other sites