[fpc-devel] Object upgrades

Nikolay Nikolov nickysn at gmail.com
Thu May 30 00:51:46 CEST 2019


On 5/27/19 1:08 AM, Ryan Joseph wrote:
> Records don’t have a VMT table and overriding but otherwise they’re the same afaik (constructors don’t work the same also). Operator overloads simply aren’t enabled for objects because apparently they’re a legacy syntax but as you pointed out they’re still useful.

Are you sure about the operator overloads? I'm pretty sure I've used 
them on objects since FPC 1.0.x (even before that) and they've always 
worked fine. They are also used by some of the PTCPas example programs, 
which are shipped with FPC and also work fine. I even tested it again 
with a trivial example. Here it is: It works with FPC 3.0.4 and almost 
certainly FPC trunk as well:

type
   TMyObject = object
   end;

operator + (a, b: TMyObject) res: TMyObject;
begin
   Writeln('Plus operator! yeah!');
end;

var
   a, b, c: TMyObject;
begin
   c := a + b;
end.

So, what's with all this FUD surrounding operator overloading not 
working with objects? Did you even test it, before screaming "legacy!"? :)

Nikolay




More information about the fpc-devel mailing list