[英]Why is class of T not allowed in a generic type?
Consider this program: 考虑这个程序:
type
TMyClass<T: class> = class
public type
TClassOfT = class of T;
end;
begin
end.
This fails to compile at the declaration of TClassOfT
with the error message: 这无法在
TClassOfT
的声明中编译,并显示错误消息:
E2021 Class type required
Can anyone explain why this is so? 任何人都可以解释为什么会这样吗? If I were to instantiate this class with, for instance
TMyClass<TObject>
then surely class of TObject
would be meaningful. 如果我要使用例如
TMyClass<TObject>
来实例化这个类,那么肯定class of TObject
是有意义的。 I constrained the generic parameter to be a class. 我将泛型参数约束为一个类。 So how can the compiler object that
T
is not a class type? 那么编译器如何反对
T
不是类类型呢?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.