How to use mixin import code outside the class definition.

Brian via Digitalmars-d digitalmars-d at puremagic.com
Mon Jan 9 10:57:05 PST 2017


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

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

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

     b = new Foo();
     mixin(b, Bar());
     b.func();      // calls Bar.func()
}

It's crazy idea?


More information about the Digitalmars-d mailing list