procedure Test<TType: class, constructor>;
procedure TTestClass.Test<TType>;
var
Obj1: IInterface;
begin
Obj1 := TType.Create as IInterface;
end;
给出以下编译错误:
[DCC错误] TestCNCTypesSerialization.pas(76):E2015运算符不适用于此操作数类型
我不明白为什么。而且我找不到办法使这项工作...
谢谢!
编译器没有理由相信泛型类型可以实现IInterface
。您没有将泛型类型限制为从实现的类派生IInterface
。
您可以通过这种方式来限制类,但这可能太过严格了。或者使用Supports
获取接口。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句