Header Inclusion problems
Can someone please check out this code and tell me why it won''t compile. Thanks.
http://cronus.spaceports.com/~hose72/mgen.zip
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement