I tried writing the following to see if I could simulate generic methods in Free Pascal 3 by combining its support for generic class functions and nested classes:
{$mode delphi}
type TFoo = class
public
type TBar<T> = class
class function Min(const A, B: T): T;
end;
end;
class function TFoo.TBar<T>.Min(const A, B: T): T;
begin
if A < B then
Result := A
else
Result := B;
end;
I have tried several syntactical variations, but I can't get it to compile no matter what. In this form, the compiler gives me a fatal error on line 8 (method identifier expected, Syntax error, ";" expected but "<" found).
What is the proper syntax for this, if at all possible?
A < Bcan work forTanywhere? If you find this compilable in Delphi, you should file a bug report to EMBT ;-) - VictoriaA < Bdoesn't work without type-casting (and with a type-cast, the code works fine in Delphi), but that is not the issue in question. The error is onclass function TFoo.TBar<T>.Min(const A, B: T): T;and that compiles in Delphi. - Remy Lebeau