Inheritance and virtual functions
I am writing some graphic software and I've run into a problem that I cannot resolve. Neithor text nor online reference has provided me with a solution.
Say I have a class called Circle. This class has a member function called Draw(). Inside this function it makes a call to another virtual member function called Behave(). The reason I have it set up like this is so when I derive a class from Circle, say Circle2, I can add more functionality to Draw() by inserting code into Behave(), without actually redefining Draw().
Of course to call Behave() from Draw I have to write Circle::Behave();. The result is the original Behave() is called, and not the one redefined in Circle2, even though it is a virtual function.
Can anyone help me with this? I know this is not how virtual functions are designed to be used, but it could greatly help the effieciency of my code. I will admit that I am a bit new to C++ (and programming in general), so any help from the C++ gurus here will be greatly appreciated.
Re: Inheritance and virtual functions
No you don't. That will force static binding (so it will always call the Cirvle version). Just write
Originally posted by Cryptomega
Of course to call Behave() from Draw I have to write Circle::Behave();
Also, if you aren't going to be redefining Draw (IE if you're just going to be redefining Behave), then the draw function does not have to be made virtual.