structs inheriting from and implementing interfaces

Steven Schveighoffer schveiguy at yahoo.com
Sat Dec 30 16:23:05 UTC 2017


On 12/29/17 7:03 AM, Mike Franklin wrote:

> 
> Is that simply because it hasn't been implemented or suggested yet for 
> D, or was there a deliberate design decision?
It was deliberate, but nothing says it can't actually be done. All an 
interface call is, is a thunk to grab the actual object, and then a call 
to the appropriate function from a static vtable. It's pretty doable to 
make a fake interface. In fact, I'm pretty sure someone did just this, I 
have no idea how far back in the forums to search, but you can probably 
find it.

Now, it would be nicer if the language itself supported it. And I don't 
see any reason why it couldn't be supported. The only issue I think 
could be an ABI difference between member calls of structs and classes, 
but I think they are the same.

-Steve


More information about the Digitalmars-d-learn mailing list