Structs implementing interfaces in D1

Tom S h3r3tic at remove.mat.uni.torun.pl
Mon Feb 9 21:37:43 PST 2009


BCS wrote:
> Hello Tom,
> 
>> BCS wrote:
>>
>>> Hello Tom,
>>>
>>>> The concept is pretty simple. The mixin creates a vtable which
>>>> points
>>>> to
>>>> a set of generated functions of the form { adjust the 'this' ptr;
>>>> jump
>>>> to the real function; }. Finally, the "InterfaceName
>>>> asInterfaceName()"
>>>> functions generated inside the struct return pointers to the
>>>> corresponding vtables.
>>> where is the vtable pointer placed?
>>>
>> In the struct instance. There will be one for each implemented
>> interface, just as with class instances.
>>
> 
> 
> 
> struct S { int i; int j; int k; int n; }
> 
> 
> S[5] sArr;
> 
> ca I make an inerface out of sArr[2] ?

Yes, there would be ways to do it, but the trick I've presented requires 
that S gets an extra field - the vtable pointer.


-- 
Tomasz Stachowiak
http://h3.team0xf.com/
h3/h3r3tic on #D freenode



More information about the Digitalmars-d mailing list