首页 > 解决方案 > 尝试在 Delphi 中结合泛型和运算符重载

问题描述

以下不起作用,我想我的意图可以从代码中读取。如果可能的话,我无法找到示例或文档。

type
  TV2<T> = record
    X: T;
    Y: T;
    class operator add(a,b: TV2<T>): TV2<T>;

  end;

TV2S = TV2<Single>;
TV2I = TV2<Int64>;


implementation

class operator TV2<T>.add(a, b: TV2<T>): TV2<T>;
begin

  Result.X := a.X + b.X; // I'm getting "E2015 Operator not applicable to this operand type"
  Result.Y := a.Y + b.Y; // I'm getting "E2015 Operator not applicable to this operand type"

end;

标签: delphigenericsoperator-overloading

解决方案


推荐阅读