ID:277155
 
I am currently having problems with referencing to a child using the parent class. Here is the code I'm trying to use:

class Global
{
//Variables
public:
Global();
static IrrlichtDevice* Idevice;
static video::IVideoDriver* Idriver;
static scene::ISceneManager* Iscene;
static gui::IGUIEnvironment* Igui;
static core::array<Model> Iscenenodes;
static core::array<Camera> Cameras;
static bool isdebugged;
};


Now Model and Camera are both childs of global. In a global array I have set it's type to Model and Camera and I get an error:

14 C:\Documents and Settings\Owner\Desktop\Easy Engine\Global.h `Model' was not declared in this scope

Does anyone know how I would fix this. I haven't learnt how to reference to a child inside a parent yet. Thanks.
What do you mean by "child"? Subclass?
In response to Crispy
Yes, subclass. Model and Camera inherit Globals members.
In response to ADT_CLONE
The design of having a class reference an instance of a subclass like that is a bit odd, but whatever floats your boat...

I think your problem is that you've got a recursive definition. Remember that C++ reads from the top down, so this won't work:

class MyClass {
OtherClass abc; // Error: OtherClass not declared yet!
}

class OtherClass: MyClass { // OtherClass is only declared from this point onwards
int value;
}


But if you reverse the definitions, that won't work either!

class OtherClass: MyClass {   // Error: MyClass not declared yet!
int value;
}

class MyClass { // MyClass is only declared from this point onwards
OtherClass abc;
}


To solve this, you can put in a forward declaration (the purpose of which is merely to tell the compiler to shut up, something you have to do a lot when programming in C++):

class OtherClass; // OtherClass is now declared

class MyClass {
OtherClass abc; // Okay, OtherClass was declared above
}

class OtherClass: MyClass { // Okay, MyClass was declared above
int value;
}
In response to Crispy
Ok, thanks for that. Though it may be a little hard, because I've made use of a lot of header files. Though I'll just change the include order.
In response to ADT_CLONE
ADT_CLONE wrote:
Though it may be a little hard, because I've made use of a lot of header files. Though I'll just change the include order.

Welcome to C++! =P

It's a sign of a badly-designed system when the order in which you include external modules actually matters... if only C++ had been created with proper module support (like almost all modern languages) it would be a lot easier to use!