Hi all,
playing around with generics for a while, however I stumbled over a problem which it seems I cannot figure out by my self:
I try to call a overloaded function from within a function specialized from a template.
The code below is a very simple example, but the problem seems quite reasonable, e.g. all calculations are the same for the special datatypes except some require rounding the result or something like that.
The idea was to move the data type dependent code to overloaded functions and keep all the rest in the template. (Bad idea ?
)
program project1;
type
generic Tdostd<_T> = class
public
type Tvariable = _T;
function doit(a: Tvariable):Tvariable;
end;
function myfun(a:double):double;
begin
result:=a+1.0;
end;
function myfun(a:string):string;
begin
result:=a+'Hi all';
end;
function Tdostd.doit(a: Tdostd.Tvariable):Tdostd.Tvariable;
begin
result:=myfun(a);
end;
type
TdoitDouble = specialize Tdostd<double>;
TdoitString = specialize Tdostd<string>;
begin
end.
However the result is:
Compile Project, Target: project1: Exit code 256, Errors: 1, Hints: 2
project1.lpr(25,11) Error: Can't determine which overloaded function to call
project1.lpr(17,10) Hint: Found declaration: myfun(AnsiString):AnsiString;
project1.lpr(11,10) Hint: Found declaration: myfun(Double):Double;
Could you please give me a hint how to correct the code or the whole approach?
Thank you very much,