On 3/26/23 14:30, Martin Frb via fpc-devel wrote:
>    generic GenLinkedList<D, T> = class
>      Data: D;
>      Next: T;
>    end;
>    TSome = class;
>    TSome = class(specialize GenLinkedList<integer, TSome>);

AFAIK "specialize" essentially "pastes" the parameters (after some checking) so it'd be as if you had declared...

    TSome = class;
    GenLinkedList = class
      Data: Integer;
      Next: TSome;
    end;
    TSome = class(GenLinkedList);

...which is perfectly valid Free Pascal code.

Also AFAIK the reason the others do not work is because when specialize is called, TFoo and TBar are not known to the compiler yet, but the forward declaration with TSome tells to the compiler that it is a class.

I guess it *is* a bit inconsistent that you can use the name of the type you are declaring during the declaration itself for classes - like "TFoo = class Foo: TFoo; end" - or target a type with a pointer before the targeted type is even known and yet specialization needs to know ahead of time everything, but that's how things are :-P

Kostas

_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply via email to