reimplementing an interface in a derived class
Ali Çehreli
acehreli at yahoo.com
Fri Jan 4 23:05:11 UTC 2019
On 01/04/2019 01:08 PM, Ali Çehreli wrote:
> There is only one vtbl per class object
Correcting myself after reading Neia Neutuladh's post: I should have
said "There is only one vtbl per class type". Every class object has a
vtbl pointer that points at its type's vtbl.
So, it's normally two pointer hops to execute a virtual function:
1) Get the object's vtbl pointer to reach the vtbl of that type; pseudo
code:
v = o.vtbl_ptr
2) Get the function pointer from a slot in that table (assuming foo()
happens to be at index 5); pseudo code:
f = v[5] // This must be a generic type like void*
3) Call the function by passing arguments; pseudo code:
alias F = TheActualTypeOfTheMemberFunction;
(cast(F)f)(42, "hello", ...)
Ali
More information about the Digitalmars-d-learn
mailing list