Operator Overloading

Top  Previous  Next

New features since Delphi 7 > Operator Overloading

 

 

 

http://docwiki.embarcadero.com/RADStudio/Tokyo/en/Operator_Overloading_(Delphi)

 

The following table maps the signatures of Delphi operators to the signatures of the according operators in C++:

 

 

 

Delphi Declaration Signature

Symbol Mapping

C++ Declaration Signature

 

 

 

Implicit(a : type) : resultType;

implicit typecast

type(int A); / operator resultType () const

Explicit(a: type) : resultType;

explicit typecast

explicit type(int A); / explicit operator resultType () const

Negative(a: type) : resultType;

-

type operator - () const;

Positive(a: type): resultType;

+

type operator + () const;

Inc(a: type) : resultType;

Inc

type & operator ++ ();

Dec(a: type): resultType;

Dec

type & operator -- ();

LogicalNot(a: type): resultType;

not

type operator ! () const;

Trunc(a: type): resultType;

Trunc

static __int64 Trunc(const TMyClass& Value);

Round(a: type): resultType;

Round

static __int64 Round(const type Value);

In(a: type; b: type) : Boolean;

in

friend bool IsContained(const type A, const type B);

Equal(a: type; b: type) : Boolean;

=

friend bool operator == (const type A, const type B);

NotEqual(a: type; b: type): Boolean;

<>

friend bool operator != (const type A, const type B);

GreaterThan(a: type; b: type) Boolean;

>

friend bool operator > (const type A, const type B);

GreaterThanOrEqual(a: type; b: type): Boolean;

>=

friend bool operator >= (const type A, const type B);

LessThan(a: type; b: type): Boolean;

<

friend bool operator < (const type A, const type B);

LessThanOrEqual(a: type; b: type): Boolean;

<=

friend bool operator <= (const type A, const type B);

Add(a: type; b: type): resultType;

+

friend resultType operator + (const type A, const type B);

Subtract(a: type; b: type) : resultType;

-

friend resultType operator - (const type A, const type B);

Multiply(a: type; b: type) : resultType;

*

friend resultType operator * (const type A, const type B);

Divide(a: type; b: type) : resultType;

/

friend resultType operator / (const type A, const type B);

IntDivide(a: type; b: type): resultType;

div

friend resultType operator / (const type A, const type B);

Modulus(a: type; b: type): resultType;

mod

friend resultType operator % (const type A, const type B);

LeftShift(a: type; b: type): resultType;

shl

friend resultType operator << (const type A, const type B);

RightShift(a: type; b: type): resultType;

shr

friend resultType operator >> (const type A, const type B);

LogicalAnd(a: type; b: type): resultType;

and

friend resultType operator && (const type A, bool B);

LogicalOr(a: type; b: type): resultType;

or

friend resultType operator || (const type A, bool B);

LogicalXor(a: type; b: type): resultType;

xor

friend resultType operator XOR (const type A, bool B); // doesn't exist

BitwiseAnd(a: type; b: type): resultType;

and

friend resultType operator & (const type A, bool B);

BitwiseOr(a: type; b: type): resultType;

or

friend resultType operator | (const type A, bool B);

BitwiseXor(a: type; b: type): resultType;

xor


 

 

 

 

All Delphi declarations have the signature of functions with parameters and a return type. In C++ however, some operators don't return a value, but operate on the class instance itself.

 

The binary operators in C++ are formed like their counterparts in C++ and therefore the translation is straightforward.
The code for the unary operators Negative, Positive, LogicalNot, Inc and Dec has to be remodeled at the C++ translation.
The conversion operators have to be remodeled too. Dependant on the direction of the conversion - to the class or from the class - the translation has to be done differently.
Finally there are more operators in Delphi like Trunc or In which aren't operators in C++.

 

 

 



This page belongs to the DelphiXE2Cpp11 Documentation

DelphiXE2Cpp11 home  Content