[fpc-pascal] Is there a way to create a generic pointer to a generic record

Sven Barth pascaldragon at googlemail.com
Sun Nov 20 12:03:40 CET 2016


Am 20.11.2016 08:31 schrieb "Le Duc Hieu" <alaviss0 at gmail.com>:
>
> Here is the complete snippet that i wanted to create
>
>
> Type
>   generic PGList<T> = ^specialize TGList<T>;
>
>   generic TGList<T> = record
>     data: T;
>     next: specialize PGList<T>
>   end;

You'll need to use nested types (they require modeswitch advancedrecords),
like this:

=== code begin ===

type
  generic TGList<T> = record
  public type
    TSelf = specialize TGList<T>;
    PGList = ^TSelf;
  public
    data: T;
    next: PGList;
  end;

=== code end ===

Note: the TSelf construct is currently needed due to a bug in the compiler.

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20161120/b1eba8af/attachment.html>


More information about the fpc-pascal mailing list