You mean like this?:
module add_virtual_functions;

import std.stdio : writeln;

void main()
{
    test();
}

mixin template Foo()
{
    void func()
    {
        writeln("Foo.func()");
    }
}

class Bar
{
    void func()
    {
        writeln("Bar.func()");
    }
}

class Code : Bar
{
    mixin Foo;
}

void test()
{
    Bar b = new Bar();
    b.func();   // calls Bar.func()

    Code c = new Code();
    c.func();   // calls Code.func()
}


On Wed, Sep 1, 2010 at 11:30 PM, Jacob Carlborg <[email protected]> wrote:
> On 2010-09-01 22:44, Philippe Sigaud wrote:
>>
>> On Wed, Sep 1, 2010 at 18:13, retard <[email protected]> wrote:
>>
>>
>>    Have you taken a loot at Scala & traits already? It would be a great
>>    starting point.
>>
>>
>> Scala's traits are great! Implicits in Scala are quite interesting too.
>> Also, Haskell typeclasses
>>
>> I wonder if D can have part of Scala traits functionality with mixins?
>
> You can't use D template mixins to add methods that will overload existing
> methods.
>
>
> --
> /Jacob Carlborg
>

Reply via email to