[fpc-devel]Operator overloading question.

BiPolar BiPolar at SoftHome.net
Fri Nov 7 03:23:26 CET 2003


Hello.

While trying to use the operator overload feature of FPC, I find out a 
restriction not mentioned on the documentation. One can overload 
several operators but not the comparison one (=); this, at least, while 
operating on classes.

The code below shows this situation (commenting out the "=" operator 
gives no error)

Please, disregard this message if this is "as it should be". But I 
think that a small paragraph mentioning this "issue" could be included 
on the docs.

Thanks for your work.

Oscar Lesta. (not on the mail list, please CC any reply)

----------------------------------------------------------------------
unit foo;

interface

type
  TSomeClass = class
    value1, value2 : Byte;
  end;

operator + (const a, b : TSomeClass) : TSomeClass;
operator = (const a, b : TSomeClass) : Boolean;

implementation

operator + (const a, b : TSomeClass) : TSomeClass;
begin
  Result.x := a.value1 + b.value1;
  Result.y := a.value2 + b.value2;
end;

operator = (const a, b : TSomeClass) : Boolean;
begin
  Result := (a.value1 = b.value1) and (a.value2 = b.value1);
end;

end.
----------------------------------------------------------------------




More information about the fpc-devel mailing list