[fpc-pascal] Handling virtual abstract method in case of generics

Sven Barth pascaldragon at googlemail.com
Fri Sep 5 20:52:45 CEST 2014


Am 05.09.2014 16:03 schrieb "Xiangrong Fang" <xrfang at gmail.com>:
>
> Hi all,
>
> I am having trouble with the following code:
>
>   generic TVector<T> = class
>   type
>     DataType = array of T;
>   private
>     //...
>   protected
>     //...
>   public
>     //...
>   end;
>
>   generic TSortableVector<T> = class(specialize TVector<T>)
>   protected
>     function OnSort(v1, v2: T): Integer; virtual; abstract;
>     //...
>   public
>     procedure Sort(Reversed: Boolean = False; OldOrder: PIntegerDynArray
= nil);
>     //...
>   end;
>
>   TIntegerVector = class(specialize TSortableVector<Integer>)
>   protected
>     function OnSort(v1, v2: Integer): Integer; override;
>   end;
>
> The error I got is:
>
> Error: Forward declaration not solved
"TIntegerVector.TSortableVector$LongInt.OnSort(LongInt,LongInt):LongInt;"
>
> The original code of vector is here:
>
> https://github.com/xrfang/fpcollection/blob/master/src/units/vector.pas
>
> I am having trouble with the original code while specializing TVector
with a Record type that does not have comparison operators.  So I decide to
make OnSort() abstract, and add it whenever needed.
>
> I am running FPC 2.6.4 on Linux x64.

Please test first with 2.7.1. If it does work there, then you'll need to
wait till it is released, otherwise you can open a bug report (with a
simplified example please, just the virtual method should be enough).

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


More information about the fpc-pascal mailing list