试图在Delphi中结合泛型和运算符重载

时间:2019-02-19 16:28:56

标签: delphi generics operator-overloading

以下内容无效,我想我的意图可以从代码中读取。如果可能,我找不到示例或文档。

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;

0 个答案:

没有答案