天天看點

D用`插件模闆`實作多繼承.

import core.stdc.stdio;
extern(C):
//import std.stdio;
mixin template A(int I){
    void f(){
        printf("%i",I*2);
    }
}
mixin template C(int I){
    void b(){
        printf("%i",I*5);
    }
}
struct B(int I){
    mixin A!I;
    mixin C!I;
    void g(){//
        f();b();
        printf("%i",I*3);
    }
}
void main()
{
    B!3 b;
    b.g();

}      

繼續閱讀