Is this a bug or did I do something wrong? The minus operator overload seems to be getting confused and I get a "Can't determine which overloaded function to call" error as a result.

{$mode objfpc}

{$modeswitch advancedrecords}

program generic_vector;

uses

Math;

type

generic TVec2<TScalar> = record

x, y: TScalar;

function Magnitude: TScalar;

function Distance (vec: TVec2): TScalar;

class operator - (left, right: TVec2): TVec2;

class operator - (left: TVec2; right: TScalar): TVec2;

end;

TVec2f = specialize TVec2<Float>;

TVec2i = specialize TVec2<Integer>;

function TVec2.Magnitude: TScalar;

begin

result := (x ** 2) + (y ** 2);

end;

function TVec2.Distance (vec: TVec2): TScalar;

begin

// ----->>> ERROR: Can't determine which overloaded function to call

result := (self - vec).Magnitude;

end;

class operator TVec2.- (left, right: TVec2): TVec2;

begin

result.x := left.x - right.x;

result.y := left.y - right.y;

end;

class operator TVec2.- (left: TVec2; right: TScalar): TVec2;

begin

result.x := left.x - right;

result.y := left.y - right;

end;

begin

end.

Regards,

Ryan Joseph

_______________________________________________

fpc-pascal maillist -

[hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal