Archived

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

Bullmax

Trouble with classes includes !

Recommended Posts

Hello, I''m quite experienced with game programming, but my problem is a newbie one... I have troubles with includes. I have various classes for like : - CCast - CMember - CScene - CSprite - CScript CCast : Library of medias Does not have inheritance, but have CMember** (list of childs) type inside it. CMember : Any media Does not have inheritance, but have CCast* (parent) type inside it. CScene : Scene with objects Does not have inheritance, but have CSprite** (list of childs) type inside it CSprite : Instance of bitmap member Inherits from CScript (because it is also a script) and have CMember* (media reference) type inside it. CScript : Linked nodes of execution Does not have inheritance, but have CScript** (list of childs) and CScript* (parent) type inside it. To declare safely, I define my classes before use in a file named "Classes.h" like this : class CCast; class CMember; class CScene; class CSprite; class CScript; Then it is followed by includes of their header containing all the complete class declaration like this : #include "CCast.h" #include "CMember.h" #include "CScene.h" #include "CSprite.h" #include "CScript.h" In each header I have the complete class declaration. The problem is with "CSprite" when I do inheritance like this class CSprite : public CScript { public: CScript(); ~CScript(); Render(); public: CMember *m_pMember; POINT m_ptPosition; FLOAT m_fRotation; POINT m_ptSize; INT m_intZ; DWORD m_dwColoration; }; The compiler gives me an error in the declaration of the class "class CSprite : public CScript" telling me that it has not been declared ! but it is, no ? Also, the compiler does not give me an error for my "CMember *m_pMember" class member ! it is I, or there is a lack of logic here... thanks in advance
/* Bullmax */ ------------- Reality has many forms : good and evil, black and white, ying and yang. [edited by - Bullmax on November 1, 2002 9:38:30 PM]
/* Bullmax */ ------------- Reality has many forms : good and evil, black and white, ying and yang.

Share this post


Link to post
Share on other sites
class CCast;
class CMember;
class CScene;
class CSprite;
class CScript;


These just tell the compiler that they are going to be declared later, so not to bitch about it. They're really only useful for declaring pointers to them, since basic pointers are all the same size.

Your problem is that the base class needs to be actually declared (it's header included first) before derived classes. The compiler needs to know what attributes are in that class before it can derive another class from it. You'll also need the classes fully declared before creating any of those types (new CScript or CScript Script; ).

[edited by - Jiia on November 1, 2002 10:32:10 PM]

Share this post


Link to post
Share on other sites
So I should include "CScript.h" before "CSprite.h" for the derivation.

And also before a class that have a "CScript" local/global variable, member or function parameter declaration.

You''re right, thanks for this reminder !



/* Bullmax */
-------------
Reality has many forms : good and evil, black and white, ying and yang.

Share this post


Link to post
Share on other sites