Am 26.04.2012 10:45 schrieb "ZHANG Dao-yuan" <1123mon...@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
_______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal