Hiding mixin template members should be allowed.

Timon Gehr timon.gehr at gmx.ch
Mon Aug 1 08:18:37 PDT 2011


I don't know since when, but hiding mixin template members was apparently
deprecated.
What about this use case? This particular instance can be resolved easily, but
what if you want to implement multiple interfaces that all want to provide
overridable default implementations using a mixin template?

If this does not work anymore, are mixin templates any good? Is there a simple
workaround I am missing?

import std.stdio;
interface Duck{
    void quack();
    void walk();
}
mixin template DuckImpl(){
    void quack(){
        writeln("quack!");
    }
    void walk(){
        writeln("walking...");
    }
}
class NormalDuck: Duck{
    mixin DuckImpl;
}
class TalkyDuck: Duck{
    void quack(){ // does not work anymore

        writeln("quack! quack!");
    }
    mixin DuckImpl;
}


void main(){
    Duck a=new NormalDuck;
    Duck b=new TalkyDuck;
    a.quack(); a.walk();
    b.quack(); b.walk();
}

tt.d(20): Error: class tt.TalkyDuck use of tt.TalkyDuck.DuckImpl!().quack()
hidden by TalkyDuck is deprecated

Cheers,
-Timon


More information about the Digitalmars-d mailing list