how should I organize my classes?
I have a window init class and an object class.
Should the window initialize the object class, or should the object class inherit from the window class?
Apparently, dev-cpp doesn't like the code below, it gives me this error:
no matching function call to 'base:base'
Now the base itself contains window type stuff, like hWNd, hdc, etc.. if I initialize a base within the inheritance as I think it is asking me to, does that mean i will have multiple copies of hwnd, hdc, etc that i don't want?
please help.. thanks.
//OPENGL obj class
class objs:public base {
private:
protected:
GLUquadricObj *quadratic;
public:
objs() { quadratic = gluNewQuadric(); }
~objs() { gluDeleteQuadric(quadratic); }
void create(int type) { type=0; };
};
I doesn't really understand what you are trying to do, but how does you base class look like?
I'm not sure what quadric object is, but if you try to create more of them this is definatly wrong since you would create a hwnd, hdc etc. everytime.
I'm not sure what quadric object is, but if you try to create more of them this is definatly wrong since you would create a hwnd, hdc etc. everytime.
Thanks CTar, I was approaching it wrong. I don't want to create alot of parents from 3 kids ;)
The kids should have the attributes of the parents, however. Just not the exact DNA.
Hope that is correct, and ++rating for you.
The kids should have the attributes of the parents, however. Just not the exact DNA.
Hope that is correct, and ++rating for you.
Not sure what you meant by "Just not the exact DNA." but, with inheritance, the derived class, the one that inherits from another, has everything that the base class has.
If you have two objects and you can look at them and say "Object A is a type of Object B", then A should inherit from B. You can call any function on object B that you would be able to on object A.
If you have two objects and you can look at them and say "Object A is a type of Object B", then A should inherit from B. You can call any function on object B that you would be able to on object A.
ok then, I'm confused.. why is this giving me an error (see first post)? Here is the 'base' class.
class base {
private:
WNDCLASS wc;
HINSTANCE hInstance;
HWND hWnd;
HDC hDC;
HGLRC hRC;
int fs; //fullscreen flag - 0=windowed, 1=no window
public:
base(HINSTANCE hInst, char * title, int xw, int yh, int bp,int val) {
//constructor
// init stuff
}
~base(){}
public:
void SetFullScreen(int);
void EnableOpenGL();
void DisableOpenGL();
void flip();
void End();
void CreateSphere(int, int, int, int);
};
class base {
private:
WNDCLASS wc;
HINSTANCE hInstance;
HWND hWnd;
HDC hDC;
HGLRC hRC;
int fs; //fullscreen flag - 0=windowed, 1=no window
public:
base(HINSTANCE hInst, char * title, int xw, int yh, int bp,int val) {
//constructor
// init stuff
}
~base(){}
public:
void SetFullScreen(int);
void EnableOpenGL();
void DisableOpenGL();
void flip();
void End();
void CreateSphere(int, int, int, int);
};
You have no default constructor available for your base class. When you try and instantiate a derived object, the compiler looks for a default constructor in base (since you didn't explicitly call one from derived) and can't find one.
This leads me to believe that your inheritence heirarchy is likely flawed. Is objs really a kind of window? If so, then it should be easy to provide construction values for it's base class.
This leads me to believe that your inheritence heirarchy is likely flawed. Is objs really a kind of window? If so, then it should be easy to provide construction values for it's base class.
you're right, my heirarchy and thinking in general is flawed.
obj should be more of an object class, i'm trying to do some data hiding to simplify my calling procedures, so that:
*BASE.CreateWindow();
- creates default window, global hdc hinstance hwnd values and msgproc
- creates base of primitives for use in opengl
I probably want to have the createwindow start an instance of the Obj class, which is what I was trying to figure out how to organize it.
I could create two separate classes, but for what purpose? I don't see the Object class using much if any of the window class; however, it would be great if the window class when initialized via constructor, initialize the Object class too. How could I get the main class to see the child class? Include it first? Or is that flawed also?
Thanks.
obj should be more of an object class, i'm trying to do some data hiding to simplify my calling procedures, so that:
*BASE.CreateWindow();
- creates default window, global hdc hinstance hwnd values and msgproc
- creates base of primitives for use in opengl
I probably want to have the createwindow start an instance of the Obj class, which is what I was trying to figure out how to organize it.
I could create two separate classes, but for what purpose? I don't see the Object class using much if any of the window class; however, it would be great if the window class when initialized via constructor, initialize the Object class too. How could I get the main class to see the child class? Include it first? Or is that flawed also?
Thanks.
I dont think you have understood what inheritance is about. Like stylin said inheritance is a "is a" relationship so is this true: objs is a base?, if it aren't you have a problem with your design. I guess what you want is a window to manage "objs"s right? Then you should have an container(std::vector, array etc.) IN your window class with the objs. Also calling your window class base is not a good idea, call it window or something like that instead.
So I guess what you want is this?:
So I guess what you want is this?:
class objs{private:protected:GLUquadricObj *quadratic;public:objs() { quadratic = gluNewQuadric(); }~objs() { gluDeleteQuadric(quadratic); }void create(int type) { type=0; };};class base {private:WNDCLASS wc;HINSTANCE hInstance;HWND hWnd;HDC hDC;HGLRC hRC;int fs; //fullscreen flag - 0=windowed, 1=no windowpublic:base(HINSTANCE hInst, char * title, int xw, int yh, int bp,int val) {//constructor// init stuff}~base(){}public:void SetFullScreen(int);void EnableOpenGL();void DisableOpenGL();void flip();void End();void CreateSphere(int, int, int, int);////////////////////////////////////////////////////////////////////////////// Added everything below this line:////////////////////////////////////////////////////////////////////////////void AddObj(objs);private:std::vector<objs> Objects;};
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement