扩展模板中的类(D)

时间:2013-11-17 18:58:10

标签: class templates d

如何在D中扩展模板内的类?

template A {
    abstract class B {}
}
class C : B {}

我如何从A外扩展B?

1 个答案:

答案 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;
}