[fpc-pascal] "Double" specialization of generic class

Sven Barth pascaldragon at googlemail.com
Tue Apr 15 14:26:21 CEST 2014


Am 15.04.2014 11:52 schrieb "Xiangrong Fang" <xrfang at gmail.com>:
> While the following program generate different error:
>
> program vectr;
> uses
>   treap, vector;
> type
>   TNodeHash = specialize TTreap<Integer, string>;
>   TNodeVector = class(specialize TVector<TNodeHash>)
>   protected
>     function OnSort(v1, v2: T): Integer; override;
>   end;
>
> operator <(nh1, nh2: TNodeHash): Boolean;
> begin
>   Result := nh1.Count < nh2.Count;
> end;
> operator >(nh1, nh2: TNodeHash): Boolean;
> begin
>   Result := nh1.Count > nh2.Count;
> end;
>
> function TNodeVector.OnSort(v1, v2: T): Integer;
> begin
>   Result := 0;
> end;
>
> begin
> end.    ​
>
> gives error message:
>
> vector.pas(149,9) Error: Operator is not overloaded:
"TTreap$LongInt$AnsiString" < "TTreap$LongInt$AnsiString"
> vector.pas(151,14) Error: Operator is not overloaded:
"TTreap$LongInt$AnsiString" > "TTreap$LongInt$AnsiString"
> vectr.lpr(28) Fatal: There were 2 errors compiling module, stopping

Operator overloads must be available in the scope the generic type was
*declared* in, not the scope it is *specialized* in. Currently this is only
possible by using records that contain operator overloads ("class
operator") and using those to specialize the generic. So you'll need to
create a container record that contains your TTreap specialization
TNodeHash and the operator overloads for > and < and specialize TVector
with that.

I have an idea to improve this situation for non-Delphi mode generics, but
that wouldn't help you with 2.6.x ;)

> While in my real program, I have this:
>
> type
>   TCmhWaves = specialize TVector<TCmhWave>;
>
> The thing is, even if I do NOT use this definition at all, it still
crashes the compiler.  By "crash" I mean I get this from lazarus:
>
> Compiling wmodel.lError: /usr/bin/ppcx64 can't be executed, error
message: Failed to execute "/usr/bin/ppcx64", error code: -139

Is there really a "ppcx64" in /usr/bin? And is it really executable? (try
"/usr/bin/ppcx64 -i" in a shell) Also check you Lazarus settings that
you've setup the correct "fpc" binary and that you project's target
settings are set to the correct platform (maybe you are trying to compile
for x86_64 without having a x84_64 compiler installed).

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


More information about the fpc-pascal mailing list