is it possible (in Delphi) to overload operators in classes. I've read some time ago it is possible only for records but I found information that for classes too like in code below:
type
TMyClass = class
class operator Implicit(a: Integer): TMyClass;
end;
class operator TMyClass.Implicit(a: Integer): TMyClass;
begin
// ...
end;
It is (modified) from address: http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/devcommon/operatoroverloads_xml.html
But when I try to use it (inside Delphi XE) I get:
PROCEDURE, FUNCTION, PROPERTY, or VAR expected (E2123)
I want to create my own simple class for matrix manipulating and possibility of using overloading opearators inside class is very expected opportunity.
Regars, Artik
Operator overloading for classes is available in some versions of the compiler. It is available for the .net and iOS compilers. For Windows and Mac is is not supported.
The iOS compiler can support this because it manages lifetime of class instances using ARC. If the desktop compilers ever switch to ARC then you can expect support for operator overloading.
Marco has blogged about this: http://blog.marcocantu.com/blog/class_operators_delphi.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With