d版静态函数作插件
import core.stdc.stdio : printf;
struct C {
static void f() {
printf("C\n");
}
}
struct D {
static void g() {
printf("D\n");
}
}
struct B(C,D){
void sayHello() {
printf("hello\n");
C.f();D.g();
}
}
extern (C) void main() {
B!(C,D) b;
b.sayHello();
}
下面是函数模板作别名,非常简单:
import core.stdc.stdio : printf;
void f(int I)() {
printf("C\n");
printf("%i",I);
}
void g(I)() {
printf("D\n");
printf(I.stringof);
}
void sayHello(alias F,alias G,int I)() {
printf("hello\n");
F!I();G!string();
}
extern (C) void main() {
sayHello!(f,g,4)();
}
上面都可在BetterC下编译!
浙公网安备 33010602011771号