Skip to main content
gamedev.net
🔒 Locked

Undefined class

Started by Leadorn 3 replies 400+ views
Original Post
Leadorn
Leadorn
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
Tazel
Tazel
Why are you using predefined classes? In the example you gave us, just doing it normally wo;uld be fine.



tcache
Contact Me
-----------
AH! MY BRAIN IS GOING TO SELF-DETONATE! -- Yours Truly (Jan, 2003)
tcacheContact Me-----------AH! MY BRAIN IS GOING TO SELF-DETONATE! -- Yours Truly (Jan, 2003)
Leadorn
Leadorn
Tried this now

class cEngine;
class cTexture: public cEngine;
class cGraphic: public cEngine;



Leadorn- Sweden

E-Mail
HomePage
Leadorn
Leadorn
because they need each other in a special way, I cant arrange them in such order. There will always be one undefined class in some other class.



Leadorn- Sweden

E-Mail
HomePage
Qw3r7yU10p!
Qw3r7yU10p!
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]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.