Abstract classes vs interfaces, casting from void*
kinke at gmx.net
Fri Aug 9 13:19:14 UTC 2019
On Friday, 9 August 2019 at 12:26:59 UTC, John Colvin wrote:
> Why is there no "hi" between 0 and 1?
Because you are treating the unadjusted object pointer as
interface pointer and then call the only virtual function of that
interface, in the 2nd vtbl slot (after the TypeInfo ptr). Casting
a class ref to an interface offsets the pointer, so that the
interface ref points to the interface vptr for that object
instance. This is missing in that line, and so you are invoking
the first virtual function of class C, which is some base
function in `Object`.
More information about the Digitalmars-d-learn