简体   繁体   English

是否可以从外部类提供的通用类型派生嵌套类?

[英]Is it possible to derive nested class from generic type provided by outer class?

I'd like to create a nested class which is based on the type provided to the outer class. 我想创建一个基于提供给外部类的类型的嵌套类。 I need the inner class to extend T by some members: 我需要内部类将T扩展为某些成员:

TOuterClass<T:class> = class
  type
    TNestedClass = class(T)
      MoreData:Integer;
    end;
end;

The compiler says "No" or more specifically [DCC Error] MyUnit.pas(20): E2021 Class type required at class(T) . 编译器说“否”或更具体地说[DCC错误] MyUnit.pas(20):E2021 class(T) 所需的类类型

Is it somehow possible to achieve what I am trying to do? 是否可以通过某种方式实现我想做的事情?

不,那不可能。

Not yet. 还没。 It probably should, but the compiler doesn't really think through all the ramifications of generic constraints yet. 也许应该,但是编译器还没有真正考虑过通用约束的所有后果。 You should add this into QC as a feature request. 您应该将此作为功能请求添加到QC中。

No but you can in a derived class that has resolved the type of T: 不可以,但是您可以在已解决T类型的派生类中:

TOuterClass<T:class> = class
  //Data
end;

TDerived = class(TOuterClass<TObject>)
  type
    TNestedClass = class(TObject)
      MoreData:Integer;
    end;
end;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM