Structs implementing interfaces in D1

Tom S h3r3tic at remove.mat.uni.torun.pl
Tue Feb 10 15:40:28 PST 2009


Tim M wrote:
> Is there a reason to have structs instead of classes/objects to do 
> whatever you use them for or is that besides the point?

Structs are more lightweight because they don't carry the 'monitor' and 
vtable pointer. It's also easier to create them on the stack e.g. in 
arrays. But my code was mostly a proof of concept implementation, since 
many folks did not realize that structs might implement interfaces too. 
It would also be possible to do more exotic stuff, like constructing 
interface 'instances' out of free functions at runtime. My point was to 
show one possible way.


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



More information about the Digitalmars-d mailing list