I want to inherit a class named CSprite from another class named CDocument before the CDocument actually declared, as some members of CDocument class are actually CSprite. I hope it don’t seems confusing? Here is my code:
class CSprite: public CDocument {}
class CDocument
{
public:
CDocument();
~CDocument();
CSprite * AddSprite(string Name);
CSprite * GetSprite(string Name);
};
I’m getting “base class undefined” error. I’m wondering may be this is not possible at all. Is it? The reason I’m doing this is increasing my code readability. Every document can have many sprites. Sprites are documents actually which can have other sprites inside them.
As CDocument.AddSprite/GetSprite both return a CSprite pointer, you may only need to declare the existence of CSprite in the document.
You can define CSprite Later in this file or in another, at which point you should be able to inherit CDocument. Although if run into more problems, you may want to redesign the object structure.