Sign in Join

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

Mailing lists / fpc-pascal / 2017-02

Overriding generic methods

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

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

Ryan Joseph

Is overriding methods from specialized generic classes supported in any way? I tried the following below but it doesn’t seem to work.

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

Regards,
Ryan Joseph

Marco van de Voort
to Ryan Joseph

In our previous episode, Ryan Joseph said:

Show quoted text 5 lines
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.
Ryan Joseph
to Marco van de Voort

Of course, I should have known. I’m just recently getting started on generics and finding some uses for them. Thanks.

On Feb 10, 2017, at 3:22 PM, Marco van de Voort wrote: After specialization, the method signature now substitutes tobject for T, so try

Regards,
Ryan Joseph