Archived

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

Leadorn

Undefined class

Recommended Posts

Hi Im having problem with classes that isent defined. Im having classes that are using eachother. So therefore I need to define them in the top of the file. What am I doing wrong? class cTexture;//inheritance from cEngine class cGraphic;//inheritance from cEngine class cEngine;//BaseClass struct sTexture; class cEngine {...}; class cTexture : public cEngine {...}; class cGraphic: public cEngine {...}; error C2079: ''Graphic'' uses undefined class ''cGraphic'' error C2079: ''Texture'' uses undefined class ''cTexture''
Leadorn- Sweden
E-Mail HomePage

Share this post


Link to post
Share on other sites
When you define classes you are defining a new type for c++. Part of defining it correctly is letting the compiler know the size of the type, ie how much memory it will take up. To do this correctly all the sizes of members of the class have to be able to be seen. Built in types are fine but other user defined types have to be included before the new type.

If they are pointers or references you can get away with forward declarations as the sizes of pointers and references doesn't change with type and is known by the compiler.

ie
class cTexture

class shape {
cTexture* pTexture_;
};

If a class is being derived it also has to be able to see the complete definition of the base class

ie

#include "base.h"

class derived : public base {
...
};

This means you can't ever have one class dervied from another which is derived from the first etc. The size of the base class has to be well defined.

So if you think all this through in your headers you should be fine. I'll give you a hint though. Split them up into seperate headers for each class first, it'll make it easier.

[edited by - petewood on January 18, 2003 12:01:10 PM]

Share this post


Link to post
Share on other sites