E2511类型参数'T'必须是类类型编译器错误意味着什么? [英] What does the E2511 Type parameter 'T' must be a class type compiler error mean?

查看:109
本文介绍了E2511类型参数'T'必须是类类型编译器错误意味着什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

遵循我的上一个问题,我试图从一个答案中编译代码

 类型
TSearchableObjectList< T> = class(TObjectList< T>)
end;

编译器不会编译它并报告这个错误信息:

 
[dcc32错误]:E2511类型参数'T'必须是类类型

这个错误信息是什么意思,我该如何修复代码? ; 包含一个通用约束 T 是一个类。类型声明如下:

 类型
TObjectList< T:class> = class(TList< T>)
...
end;

您可能认为约束是继承的,但事实并非如此。所以你需要在你的课堂中包含约束。指定约束如下:

 类型
TSearchableObjectList< T:class> = class(TObjectList< T>)
...
end;


Following my previous question, I am attempting to compile the code from one of the answers there.

 type 
   TSearchableObjectList<T> = class(TObjectList<T>)
   end;

The compiler will not compile this and reports this error message:

[dcc32 Error]: E2511 Type parameter 'T' must be a class type

What does this error message mean, and how should I fix the code?

解决方案

TObjectList<T> includes a generic constraint that T is a class. The type declaration is as follows:

type
  TObjectList<T: class> = class(TList<T>)
    ...
  end;

You might think that constraints are inherited, but that is not the case. And so you need to include the constraint in your class. Specify the constraint like so:

type
  TSearchableObjectList<T: class> = class(TObjectList<T>)
    ...
  end;

这篇关于E2511类型参数'T'必须是类类型编译器错误意味着什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆