So I am trying to make a project that mirrors Ruby's Gosu gem, a 2d graphics plugin. To do this, I have created a class called Window, which is intended to be inherited from (class Game: public Window), and then have three of its functions defined: Update()
Controls()
and Draw()
.
To accomplish this in my window class I have a defined function Show()
which looks like this
void Window::Show(){
// stuff to initialize and set up my window and controls
glutTimerFunc(100,real_update,fps);
}
And my real_update
function is simply
void Window::real_update(int v){
glutPostRedisplay();
Update();
glutTimerFunc(1000/fps,real_update,v);
}
The logic here is that whatever class inherits Window
, will be able to call Show()
, which will set up the call back loop and initialize the window, then in the real_update
loop it will call the Update
which will be defined in the child class.
However, when I create a simple child class, define Update
in the child class to just indicate it is being called, and then call Show on an instance of the child class it will only ever call the base class's (Window) definition for Update
.
I'm certain this is a misunderstanding with inheritance, but I do not understand why. I thought that the child class call to Show()
would call the base class's definition which then calls Update
, which has been changed since the child class redefines it.