overloading unary operators

Top  Previous  Next

New features since Delphi 7 > Operator Overloading > unary operators

 

While the operators Negative, Positive, LogicalNot, Inc and Dec have a parameter and a return value, in Delphi, the counterparts in C++ don't have a parameter, but return a modified copy of themselves. The code for the operator implementation has to be remodeled accordingly. This is demonstrated at the example of the Negative operator:

 

 

class operator TMyClass.Negative(a: TMyClass): TMyClass;

var

  b : TMyClass;

begin

  b:= -a.payload;  

  Result:= b;

end;

 

 

Delphi2Cpp converts this to:

 

 

TOperatorClass TOperatorClass::operator - () const

{

  TOperatorClass result = {0};

  TOperatorClass B = {0};

  B = -this->payload;  // Use the implicit conv here?

  result = B;

  return result;

}

 

 

All occurrences of the parameter are substituted by this in C++.

 

 

 

 

 

 

 

 

 

 

 



This page belongs to the Delphi2Cpp Documentation

Delphi2Cpp home  Content