www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - How to use mixin import code outside the class definition.

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?
Jan 09