[fpc-pascal] Generic with inheritance - fpc 3.0

Torsten Bonde Christiansen tc at epidata.info
Mon Nov 30 15:54:42 CET 2015


Hi.

The docs for 3.0 does not directly mention generics and inheriting from 
another generic class, but I tried out with the code below.
It compiled, ran and worked fine but since the docs do not explicit 
mention it as a posibility I am a little reluctant to go forward using 
this strategy if is not meant to work...

(ps. i know this is incomplete code, but it should illustrate my point)type

type
   { TMyType }

   generic TMyType<T> = class
   private
     Item: T;
   public
     constructor Create; virtual;
   end;

   { TMyDerivedType }

   generic TMyDerivedType<T> = class(specialize TMyType<T>)
   private
     Count: Integer;
   public
     constructor Create; override;
   end;

   TMyIntClass = specialize TMyDerivedType<Integer>;

[...snipped both Create implementations...]

var
   IC: TMyIntClass;

begin
   M := TMyIntClass.Create();
   M.Item := 20;
   M.Count := 2;
   M.Free;
end;




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20151130/02aaee45/attachment.html>


More information about the fpc-pascal mailing list