【发布时间】:2015-04-10 12:22:56
【问题描述】:
我的代码(简化为下面的 sn-p)无法编译。 Delphi XE4 的编译器返回此消息:E2250: There is no overloaded version of 'Sort' that can be called with these arguments。
program Project1;
{$APPTYPE CONSOLE}
uses
System.Generics.Collections;
type
TSomeGenericType<TKey, TData> = class (TObject);
function GetSortedArray: TArray<TSomeGenericType<Integer, TObject>>;
begin
// ... omitted code to initialize Result
TArray.Sort<TSomeGenericType<Integer, TObject>(Result);
// !!! E2250: There is no overloaded version of 'Sort' that can be called with these
// arguments
end;
begin
end.
【问题讨论】:
-
感觉就像一个编译器错误。什么是 TSomeType?什么delphi版本?
-
可行的解决方法是使用局部变量,将其传递给 Sort,然后分配给 Result。也许编译器对这里的 Result 感到困惑。我也想知道为什么没有 MCVE。
-
您的编辑简直是一场灾难。您的任何代码都无法远程编译。我敦促你制作一个 MCVE。我没有看到编译器错误的证据。我所能看到的是你有一个问题,你还没有向我们证明。因此,这个问题目前是题外话。
-
不是bug,是我的错字造成的。我将编辑问题并很快提供答案。 @DavidHeffernan,你在 MCVE 上是完全正确的,当我开始创建一个我认识到我的错误时。
-
是的,你少了一个 >。很高兴您实际演示了 MCVE 的强大功能! ;-) 感谢收听!哦,我还削减了代码,使其成为更简洁的 MCVE。这也很重要。
标签: delphi generics delphi-xe4