سؤال

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top