samedi 19 avril 2014

héritage - VTable C++ application multi-parent des hiérarchies polymorphe - Stack Overflow


If I have


A <- B (where both are polymorphic)


there are two levels of indirection when calling a function on B. Firstly a look up to determine what type of A object and then a lookup to find the function amongst all of B's.


Now if I had:


A <- B <-C (and all are polymorphic classes)


does this mean when I call a function on C it has to go through four levels of indirection (two for B and two for A)?




There is always just a look-up in the vtable and a call of the resulting function. The depth of the inheritance tree doesn't make a difference. When multiple inheritance is involved (i.e., a class with multiple bases) it may be necessary to also adjust the pointer which becomes the this pointer.



If I have


A <- B (where both are polymorphic)


there are two levels of indirection when calling a function on B. Firstly a look up to determine what type of A object and then a lookup to find the function amongst all of B's.


Now if I had:


A <- B <-C (and all are polymorphic classes)


does this mean when I call a function on C it has to go through four levels of indirection (two for B and two for A)?



There is always just a look-up in the vtable and a call of the resulting function. The depth of the inheritance tree doesn't make a difference. When multiple inheritance is involved (i.e., a class with multiple bases) it may be necessary to also adjust the pointer which becomes the this pointer.


0 commentaires:

Enregistrer un commentaire