Abstract classes vs interfaces, casting from void*

John Colvin john.loughran.colvin at gmail.com
Fri Aug 9 13:21:54 UTC 2019


On Friday, 9 August 2019 at 13:19:14 UTC, kinke wrote:
> 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`.

Ok, makes sense, thanks.


More information about the Digitalmars-d-learn mailing list