On 23 Mar, 14:32, "wizwx" <wiz...@gmail.comwrote:
Quote:
On Mar 23, 8:12 am, Rolf Magnus <ramag...@t-online.dewrote:
>
Quote:
wizwx wrote:
Quote:
However, if I remove the keyword "virtual" in the class
ApplicationFramework and provide a definition for customize1 and
customize2, then the customize1 and customize2 in the class
ApplicationFramework are called, instead of the ones defined in the
class MyApp.
>
>
Quote:
Quote:
It seems that dynamic binding must come to play at some point. But I
don't see why this is so. Can anyone give me some helpful insight?
>
Quote:
Well, this is the sole purpose of the 'virtual' keyword. It means 'activate
dynamic binding'.
>
Can you explain more on this? Well I agree that virtual keyword
enables dynamic binding. The typical use of virtual function is that
you call it through a base pointer/reference that actually refers to
the derived class. But in this example I don't see any pointer or
reference, that's why it confuses me.
It's because templateMethod() is declared in ApplicationFramework, if
the methods are not virtual it will call those functions local to the
class, but since you declared them virtual it has to take a look at
the vtable to find the method to call.
--
Erik Wikström