In reply to Allan_mo:
Looks like I have to open this thread.
I have tried several cases and I am not clear how polymorphism works in the light of the statement made by dave about compile time binding of func2.
Please see the cases below.
Case Base Derived Resolution
1 NV ND Base
NV ND Base
2 NV NV Base
NV NV Base
3 NV V Base
NV V Base
4 V NV Derived
NV NV Derived
5 NV NV Base
V NV Derived
6 V V Derived
NV NV Derived
7 NV NV Base
V V Derived
8 V NV Derived
V NV Derived
9 V V Derived
V NV Derived
10 V V Derived
V V Derived
11 V ND Base
NV NV Base
12 V ND Base
V ND Base
Please look at the table above.
The basic code template remains as I have put in the original post.
What varies is just whether func1, func2 are defined as virtual or non virtual.
In the above table, N - virtual; NV - non virtual; ND - not defined
For example,
case 1 means the following
In base class, func1/2 are non virtual
in derived class, func1/func2 are not defined
The last column, resolution, indicates that the call P1.func1 resolves to
In this case, it resolves to func1 and func2 in base class
Let us take another case, case 5
Here,
in base class, func1 is non virtual, func2 is virtual
in derived class, func1 is virtual and func2 is non virtual
it resolves to func1 in base class and func2 in derived class
Now, what I am confused is,
How to interpret case 5, where func1 is called from base class but func2 is called from derived class. It is based on the fact that func2 is a virtual function. So, wherever func2 is declared as a virtual class, it seems there is late binding. This seems to be all true.
So I am a bit confused when Dave says that func2 is based on compile time binding.
I need some clarifications here please …
The code base is here in case anyone wants to see the source code:
https://github.com/sharanbr/assorted_verification/tree/master/polymorphism