Redefining a standard operator
In Cxx, you can redefine standard operators, and for this, Modelio Cxx Designer 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.
-
Set its name to "operator =".
-
Add a «Cxx.Operator» stereotype to the operation.
Creating a cast operator
Cxx 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.
-
Set the converted type as its name (like bool).
-
Stereotype the operation using «Cxx.Operator».
The generated code will be as follows:
operator bool();