class Engine
{
public:
Engine() {};
~Engine() {};
virtual setup() = 0;
virtual draw() = 0;
};
class OpenGLEngine: public Engine
{
OpenGLEngine() {// int stuff}
~OpenGLEngine () {//destroy stuff}
setup();
draw();
};
[/source]
Then in the main program I have got...
[source]
Engine *pGfxEngine;
switch(MODE)
{
case RENDER_SOFTWARE:
...
break;
case RENDER_OPENGL:
pGfxEngine = new OpenGLEngine();
break;
}
Anyway when I want to destroy the OpenGLEngine it will not call the OpenGLEngine destructor only the Engine desctructor.
Thanks for any help.
Sorry but another OOP question
I''m having problems with graphics engine I''m working on.
I''m currently trying to learn OOP for C++ and I thought that it would be ideal for my graphics engine because I want to implement an number of draw modes. ie Software, OpenGL, etc;
So I have got as follows at the moment:
+---------------------------------------------+| "Hard work never killed anyone but I figure || why take the chance?" Ronald Regan |+---------------------------------------------+
Make your destructor virtual.
Edited by - Jrz on December 21, 2000 11:15:05 AM
Edited by - Jrz on December 21, 2000 11:15:05 AM
Jrz is right.
Because pGfxEngine is initially an object of Engine. You are using polymorphism to access your derived class. And so when you destroy pGfxEngine it is calling Engine::~Engine() not OpenGlEngine::~OpenGlEngine(). If it was virtual, it would then call ~OpenGLEngine() before ~Engine().
Kevin =)
-----------------------------
kevin@mayday-anime.com
http://www.dainteractiveonline.com
Because pGfxEngine is initially an object of Engine. You are using polymorphism to access your derived class. And so when you destroy pGfxEngine it is calling Engine::~Engine() not OpenGlEngine::~OpenGlEngine(). If it was virtual, it would then call ~OpenGLEngine() before ~Engine().
Kevin =)
-----------------------------
kevin@mayday-anime.com
http://www.dainteractiveonline.com
-----------------------------kevin@mayday-anime.comhttp://www.mayday-anime.com
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement