Interfaces allow member definitions?

Frustrated c1514843 at drdrb.com
Thu Jan 30 11:58:42 PST 2014


On Thursday, 30 January 2014 at 17:11:24 UTC, Steven
Schveighoffer wrote:
> On Thu, 30 Jan 2014 11:58:15 -0500, Frustrated 
> <c1514843 at drdrb.com> wrote:
>
>
>> Essentially what it boils down to is treating interfaces like
>> classes that have no fields). To avoid the diamond problem 
>> simply
>> always choose the method that is not from the interface(since 
>> it
>> is "default"), which is done naturally with the vtable.
>
> It's simpler than that. A function is a block of code. A vtable 
> entry points to a block of code. Just point the vtable entry at 
> the block of code that is the default implementation.
>
> -Steve

But what if you want to provide some default behavior? We are not
dealing with abstract classes here.

Since there is currently no way to do what I am saying no
"solution" will be adequate unless it fulfills the behavior.

(again, it's not like we can't accomplish basically the same
thing, the point is mainly about simplification)

The question was about if there was any innate reason why this
type of behavior couldn't be accomplish using the vtable. I'm
assuming there is none and it could easily be done? (the compiler
just has to reserve the space and setup the pointers to the
functions?)


More information about the Digitalmars-d-learn mailing list