[fpc-pascal] Need some advice
ppadilcdx
ppadilcdx at gmail.com
Wed Jan 24 20:31:05 CET 2024
Trying to use the fgl unit, specifically the TFPGMap. Below is a
simple program I'm trying to compile; it gives me two errors:
fgl.pp(1582,18) Error: Operator is not overloaded: "pair" < "pair"
fgl.pp(1584,23) Error: Operator is not overloaded: "pair" > "pair"
program test;
{$mode objfpc}
uses
fgl;
type
pair = record
x, y : integer;
end;
operator < (a,b: pair) r:boolean;
begin
if a.x < a.y then
r := true
else
r := false;
end;
operator > (a,b: pair) r:boolean;
begin
if a.x > a.y then
r := true
else
r := false;
end;
function cmp(const a,b : pair) : LongInt;
begin
if a < b then
cmp := -1
else
if a > b then
cmp := 1
else
cmp := 0;
end;
type
TMyDict = specialize TFPGMap<pair, integer>;
var
Dict: TMyDict;
key: pair;
Value: Integer;
begin
Dict := TMyDict.Create;
Dict.OnKeyCompare := @cmp;
key.x := 2;
key.y := 4;
Dict.Add(key, 99);
Value := Dict[key];
writeln(Value);
Dict.Free;
end.
Any advice appreciated. Thanks.
Pete
More information about the fpc-pascal
mailing list