Implementing multiple inheritance in D

Jacob Carlborg doob at me.com
Tue May 10 06:26:44 PDT 2011


On 2011-05-10 10:14, kenji hara wrote:
>> Why not emulate it with interfaces and template mixins?
>
> Interfaces? I don't understand what you mean.
> So please give me a example code.
>
> Kenji Hara

interface Super {
     void foo ();
}

template SuperImpl {
     void foo () { /* do something */ }
}

class Sub : Super {
     mixin SuperImpl;

     void bar () { /* do something else */ }
}

This might not be the best solution, it won't work with existing class 
hierarchies. I've actually tried this now and it won't work, you cannot 
override the methods coming from the mixin.

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list