[fpc-pascal] generics question

Sven Barth pascaldragon at googlemail.com
Sat May 14 21:29:43 CEST 2011


I have not yet looked at the parsing of methods of generic classes 
during my work on the generics, but when I'll implement generic methods 
I'll try to take a look at your problem.

Regards,
Sven


On 12.05.2011 12:37, Adrian Veith wrote:
> Hi,
>
> I try this:
>
> type
>    TTestGen<T>  = class
>      constructor Create();
>      class function Test(val: T): string; inline;
>    end;
>
>
> function Blah(const val: Integer): string; inline; overload;
> begin
>    Result:= IntToStr(val + 1);
> end;
>
> function Blah(const val: string): string; inline; overload;
> begin
>    Result:= val + '1';
> end;
>
> { TTestGen }
>
> constructor TTestGen<T>.Create();
> begin
> end;
>
> class function TTestGen<T>.Test(val: T): string;
> begin
>    Result:= Blah(val);
> end;
>
>
> type
>    TTestInt = TTestGen<Integer>;
>    TTestString = TTestGen<String>;
>
> and get an error: can't determin which overloaded function Blah to use.
>
> It would be nice if this could work. It would be a way to inject inline
> functions into a generic class - avoiding virtual functions.
>
> BTW. If I only have one Blah and only one corresponding specialization
> it works.





More information about the fpc-pascal mailing list