Creating an operation redefinition

 

Redefining a standard operator

In C++, you can redefine standard operators, and for this, Objecteering C++ Developer lets you declare this construct.  Coplien form defined on a newly created class contains such an example.

 

<<Cxx.Operator>> operator =(in value : OperatorRedefinition):OperationRedefinition

 

To redefine a standard equality operator, the following steps should be carried out:

·         Create an operation.

·         Add a <<Cxx.Operator>> stereotype to the operation.

·         Set its name to "operator =".

·         Add a <<Cxx.Name>> tagged value to the operation, and set "=" as its parameter.

 

 

Creating a cast operator

C++ also authorizes the creation of cast operators, to allow implicit conversion between types.

 

To define a cast operator, carry out the following steps:

·         Create an operation.

·         Add a <<Cxx.Name>> tagged value to the operation, and set the converted type as its parameter (like bool).

·         Stereotype the operation using <<Cxx.Operator>>.

 

The generated code will be as follows:

 

operator bool();