+ 1
I don't understand the difference between a base class with virtual function and without it.
Seems that the examples (in the lesson "polim" and "virt. func"are the same.
2 Answers
+ 4
There is a tiny difference though. Lets call base virtual method "x". When you reload the "virtual" function in derivative class it leads to call of reloaded function in code like this:
Base *a = new Derivative();
a->x(); //calls reloaded version from Derivative
in case when "virtual" keyword is ommited, the same code:
Base *a = new Derivative();
a->x(); //calls original version from Base, despite from the fact we "reloaded" "x" in Derivative class as well
Please note in both examples we used pointer of type Base.
0
Definetely agree with Valery's explanation. However while trying to implement both proposed solutions within the "Learn c++" application emulator I noticed that the method reloaded version is always called regardless whether it's been declared virtual or not. It's seems to me, the only way to grab and verify the theory of "virtual methods" in action is through a real IDE such as "eclipse" or "Code Block"... Please confirm my assumption :-)