如何在D中扩展模板内的类?
template A {
abstract class B {}
}
class C : B {}
我如何从A外扩展B?
答案 0 :(得分:4)
您的代码无法编译,您需要指定模板参数。
a.d:3: parenthesized TemplateParameterList expected following TemplateIdentifier
我不确定您是否希望C
成为模板。
以下输出0
。
import std.stdio;
template A(T) {
abstract class B {
public T f() {
return T.init;
}
}
}
class C : A!(int).B {}
int main() {
writeln((new C()).f());
return 0;
}