Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2014-09

Handling virtual abstract method in case of generics

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Xiangrong Fang

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

Reply by email

Sven Barth
to Xiangrong Fang
"Xiangrong Fang" wrote 22 lines
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);
Show quoted text 11 lines
//... 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;"

Show quoted text 6 lines
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

Reply by email