[fpc-pascal] Overriding generic methods

Marco van de Voort marcov at stack.nl
Fri Feb 10 09:22:18 CET 2017


In our previous episode, Ryan Joseph said:
> type	
> 	TObjectListAbstract = specialize TList<TObject>;
>   TObjectList = class (TObjectListAbstract)
> 		procedure Add (value: T); override;
> 	end;	

After specialization, the method signature now substitutes tobject for T, so
try


{$mode objfpc}
type
  generic TList<T> = class (TObject)
                procedure Add (value: T); virtual;
        end;


type
        TObjectListAbstract = specialize TList<TObject>;
        TObjectList = class (TObjectListAbstract)
                procedure Add (value: TObject); override;
        end;

procedure TList.Add (value: T); 
begin
end;

procedure tobjectlist.add(value: TObject);
begin
end;

begin
end.


More information about the fpc-pascal mailing list