Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2012-04

Overloading with generic type as parmeter causes compiler error.

3 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Donald R. Ziesig

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.

Reply by email

Sven Barth
to Donald R. Ziesig
Donald R. Ziesig wrote 37 lines
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,

What version of FPC did you try with? If it was 2.6.0 or 2.6.1 or anything older then please try with a recent trunk version. I fixed this problem some weeks ago.
If you already tested with a recent trunk version of FPC than please open a bug report for the compiler with a simple example that does not depend on the LCL and should compile.

Regards,
Sven

Reply by email

Donald R. Ziesig
to Sven Barth

Hi Sven!

According to Lazarus (0.9.30.4) Help|About, fpc is version 2.6.0.

I will try with a recent trunk version (if I can figure out how to do it :-[ ) and let you know the results.

Thanks,

Don Z.

Sven Barth wrote 57 lines
On 30.04.2012 17:45, Donald R. Ziesig wrote: > 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, What version of FPC did you try with? If it was 2.6.0 or 2.6.1 or anything older then please try with a recent trunk version. I fixed this problem some weeks ago. If you already tested with a recent trunk version of FPC than please open a bug report for the compiler with a simple example that does not depend on the LCL and should compile. Regards, Sven -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email