-
Inheritence Question
Hey all,
I have classes in my application, which inside themselves create pointers to other classes which came as part of a library (Irrlicht in this case). Now I am new to OOP but I am sure this is just an inheritence issue. I am getting errors like this:
../include/config.h:32: ISO C++ forbids initialization of member `device'
../include/config.h:32: making `device' static
../include/config.h:32: invalid in-class initialization of static data member
Which I assume leads to the errors like this:
"main.cpp:184: `class Config' has no member named 'device' "
^ Even though the class does have a member named device. Now in this case this is the class where device is initalized:
Code:
class Config {
public:
// Variables
IrrlichtDevice *device = createDevice(EDT_OPENGL, dimension2d<s32>(1800, 1100), 16, false, false, false, NULL);
ISceneManager* smgr = device->getSceneManager();
IVideoDriver* driver = device->getVideoDriver();
core::stringw HelpText;
video::E_DRIVER_TYPE driverType = EDT_OPENGL;
int header;
stringc str1, str2, str3, c1, c2, c3, c4;
int header_lines, format_cols, driverType_int;
// Functions
Config();
~Config();
void ReadXML(void);
void writeConfigFile();
void updatePref();
};
and this is how I call it in main.cpp: config.device->run()
Now device is a member of the Irrlicht library, have I forgotten to inherit this library properly?
-
You don't initialize variables in a class definition, that's what the constructor is for. If you want every instance of the class to have the exact same value in those initialized variables, then you can declare them as static and initialize them outside of the class definition. Be aware, doing so with those pointers will lead to every instance pointing to the same device. You likely want to initialize those in your constructor. You should read up on OOP before you jump into it.
-
I have been reading up on it, I am just applying the knowledge now. Ok, so if I initalize them in the contructor they are accessible outside correct? Also is it neccessary to make my base class a child of the Irrlicht base class to use those pointers within mine? My instincts tell me no.
-
I got it to work, thank you for you lesson on OOP, I am sure it will serve me well