[fpc-pascal] Generic specialization using $mode objfpc
Sven Barth
pascaldragon at googlemail.com
Tue Nov 11 23:25:17 CET 2014
On 11.11.2014 22:48, silvioprog wrote:
> Oh, sorry. Just:
>
> unit Core.Singleton;
>
> {$mode objfpc}{$H+}
>
> interface
>
> type
>
> { TSingleton }
>
> generic TSingleton<T: class> = class(TObject)
> public
> class function GetInstance: T;
> end;
>
> implementation
>
> { TSingleton }
>
> class function TSingleton.GetInstance: T;
> begin
> end;
>
> end.
>
> And compiled like a charm. =)
Yes, since the ObjFPC dialect was developed without type overloading in
mind (in Delphi (and FPC's mode Delphi) you can have TSingleton<T> and
TSingleton<T, S> in the same unit) it was decided that it is not
necessary to add the <T> at the definiton of the method as well.
Regards,
Sven
More information about the fpc-pascal
mailing list