C

C++ Virtual tables:

1. A simple C++ class layout.
Layout Diagram

2. Class layout in the case of a simple inheritance
Here class dad is derived from class human ( used in case 1)
Here is the Layout diagram

3. Class layout in the case of multiple inheritance
I introduced a new base class Hero and Dad is now derived from
both Human and Hero
Here is the Layout Diagram

4. Another multiple inheritance scenario.
Here again Dad is derived from both Human and Hero. But notice that
this time I introduced the virtual function beCool() function in both Human
and hero. This is an example where we use Adjustor Thunks.
Here is the Layout Diagram

5. An invalid scenario ?
Here I have class Dad and class Mom derived from class Human.
Then class Me derives from Mom and Dad (Not virtually). So Me will have
duplicate members of Human. Excuse the names of functions in this example.
I used those to make it more readable :)
Here is the layout diagram

5. Virtual Base classes.
Coming soon :)

 


Home