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

Xiangrong Fang xrfang at gmail.com
Fri Sep 5 16:02:18 CEST 2014


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.

Thanks!

Xiangrong
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20140905/aae7a111/attachment.html>


More information about the fpc-pascal mailing list