Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2007-05

operator overloading question

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Alexey Pavluchenko

Hello all,

When trying to compile the following code

=== cut===
unit foo;
interface
  type tbar = record
    somefield: integer;
  end;
       pbar = ^tbar;
  operator + (a: pbar; b: pbar) c: pbar;
implementation
  operator + (a: pbar; b: pbar) c: pbar;
  begin
  end;
end.
=== cut===

the compiler (2.0.4) stops with the "impossible operator overload" message. Two questions arise: 1) why is it considered impossible and
2) how can I workaround this?

Best regards, Alexey
Daniël Mantione
to Alexey Pavluchenko

Op Tue, 8 May 2007, schreef Alexey Pavluchenko:

the compiler (2.0.4) stops with the "impossible operator overload" message. Two questions arise: 1) why is it considered impossible

Overloading pointers turned out to be too problematic in the past, so it was to be disabled. Overloading dynamically allocated data structures is problematic anyway due to memory management.

and 2) how can I workaround this?

You can overload Tbar instead.

Daniël