Sign in Join

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

Mailing lists / lazarus / 2010-10

operator overloading

3 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

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

Birger Jansen

Hi,

In Delphi you can overload the Explicit operator. This makes is possible to have a type TTypeX and TTypeY and cast one into the other. To do that, implement an operator overloader: operator Explicit(const AValue: TTypeX): TTypeY.

  // implement converstio from TTypeX to TTypeY.
Then you can do stuff like
var
  tx: TTypeX;
  ty: TTypeY;
begin
  tx := TTypeX.Create;
  ty := TTypeY(tx);
end;

Is something like this possible in FPC?

Kind regards,
Birger

Reply by email

Vincent Snijders
to Birger Jansen

2010/10/22 Birger Jansen :

Show quoted text 16 lines
Hi, In Delphi you can overload the Explicit operator. This makes is possible to have a type TTypeX and TTypeY and cast one into the other. To do that, implement an operator overloader: ?operator Explicit(const AValue: TTypeX): TTypeY. ?// implement converstio from TTypeX to TTypeY. Then you can do stuff like var ?tx: TTypeX; ?ty: TTypeY; begin ?tx := TTypeX.Create; ?ty := TTypeY(tx); end; Is something like this possible in FPC?

I don't know. If you don't get an answer, it may be useful to ask on the fpc-pascal mailing list, that is a better place for such questions:
http://lists.freepascal.org/mailman/listinfo/fpc-pascal/

Vincent

Reply by email