[Lazarus] Overloading with generic type as parmeter causes compiler error.
Donald R. Ziesig
donald at ziesig.org
Mon Apr 30 17:45:27 CEST 2012
Hi All!
I am working on a generic type library and ran into a problem at compile
time.
type
generic TMyType<T> = class
*
*
*
function IndexOf( Item : T ) : Integer; overload;
functionIndexOf( aName : String) : Integer; overload;
// generics1.pas Error: Function is already declared Public\Forward
"TMyType.IndexOf(AnsiString):LongInt;"
// or, reverse the declarations:
function IndexOf( aName : String ) : Integer; overload;
function IndexOf( Item : T ) : Integer; overload;
// generics1.pas Error: Function is already declared Public\Forward
"TMyType.IndexOf(<undefined type>):LongInt;"
end;
Similar errors occur in implementation of the overloaded subprograms, as in:
// generics1.pas Error: function header "IndexOf" doesn't match forward
: var name changes aName => Item
The obvious work-around is to avoid overloading with generic types as
parameters, but that is really a hack in this case.
Keep up the GREAT work,
Don Z.
More information about the Lazarus
mailing list