Give back multiple inheritance

Sean Kelly sean at f4.ca
Fri Mar 24 13:53:14 PST 2006


Kyle Furlong wrote:
> Sean Kelly wrote:
>> Johan Granberg wrote:
>>> sgrantham at sympatico.ca wrote:
>>>> one of the more powerful and useful expression
>>>> capabilities of C++ is in multiple inheritance and its loss is to 
>>>> much of a
>>>> price.
>>>
>>> I to want multiple inheritance but I got the feeling that walter 
>>> prety much have ruled that out.
>>
>> For what it's worth, mixins are a capable replacement for MI in many 
>> instances.
> 
> To bash out a quick and dirty mixin implementation:
> 
> interface Tree
> {
>     void Add(Tree item);
> }
> 
> template TreeFunctionality
> {
>     Tree Parent;
>     void Add(Tree Item)
>     {
>         Item.Parent = this;
>         LL.Add(Item);
>     }
>     // Implement LL
> }
> 
> class tFile : File, Tree // Is the the correct syntax?
> {
>     mixin TreeFunctionality;
> }
> 
> Some other more experienced design people can help make this better I'm 
> sure. But it gives you the idea.

I have a fairly old D version of C++ IOStreams that uses mixins as a 
substitute for MI.  Here's a link:

http://www.home.f4.ca/sean/d/stream.d


Sean



More information about the Digitalmars-d mailing list