[fpc-pascal] Can it map class type as key?

Sven Barth pascaldragon at googlemail.com
Thu Apr 26 12:53:14 CEST 2012


Am 26.04.2012 10:45 schrieb "ZHANG Dao-yuan" <1123monkey at gmail.com>:
>>
>> program moi;
>> {$mode objfpc}
>>    uses fgl;
>>    type
>>        tSI= specialize tFpGMap<integer, tObject>;
>>        // tIS= specialize tFpGMap<tObject, integer>;
>> begin
>> end.
>
>
> Hi,
> I'm trying to use template in fpc 2.6.0. I can map class type as value as
above code can be compiled. But if I uncomment the declaration of tIS --
map class type as key, fpc fail to compile and print out these error msgs:
>
> Error: Operator is not overloaded: "TObject" < "TObject"
> Error: Operator is not overloaded: "TObject" > "TObject"
> t.pas(10) Fatal: There were 2 errors compiling module, stopping
> Fatal: Compilation aborted
> Error: /usr/bin/ppcx64 returned an error exitcode (normal if you did not
specify a source file to be compiled)
>
> Any way to resolve it?

This has nothing to do with < and > in the declaration.
TFPGMap uses < and > comparisons for key comparisons, so these operators
need to be overloaded. You can't use global operators here, because of
scope problems, so you need to use either a different type or wrap them in
a record with operators.

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


More information about the fpc-pascal mailing list