[fpc-pascal] Generics: Error: Can't determine which overloaded function to call
LacaK
lacak at zoznam.sk
Wed Sep 18 09:07:41 CEST 2019
Hi *,
I have generics record, where one method computes distance between 2 points:
function T2DPoint.Distance(P: T2DPoint): Single;
begin
Result := Sqrt(Sqr(x-P.x) + Sqr(y-P.y));
end;
But this does not compile as there are many versions of Sqr() in the
scope Sqr(longint), Sqr(QWord), Sqr(Extended), Sqr(int64)
Point coordinates (x,y) can be either integer or single (in my case)
when specializing, so decision which version of Sqr() to call should be
postponed to specializing phase, does not?
Is there other solution as:
function T2DPoint.Distance(P: T2DPoint): Single;
var dx,dy: T;
begin
dx := x-P.x;
dy := y-P.y;
Result := Sqrt(dx*dx + dy*dy);
end;
(for integer operations Sqr() is implemented as "value*value", so there
is no difference (compared to above mentioned implementation) but for
floating point operations there is called internal function
"fpc_in_sqr_real" which is IMO implemented in smarter way that
"value*value" (I can not find where/how is implemented)?)
TIA
-Laco.
More information about the fpc-pascal
mailing list