From Xojo Documentation


Allows the class to support the Addition (+) operator to provide custom functionality.


Create an Operator_Add function in a class to specify the functionality of the + operator for that class.

In the function, the Self instance is one of the operands and the other operand is passed as a parameter. Operator_Add assumes the Self instance is on the left and the passed instance is on the right.

Sample Code

Suppose you have a class, Vector, that can store a vector of modest size. To define the + operator for this class, create a method of the Vector class called Operator_Add.

The Vector class has two Integer properties, x and y.

Operator_Add is defined as:

Function Operator_Add(rhs As Vector) As Vector
// rhs stands for right-hand-side, the vector to be added to Self
Var ret As New Vector // the sum of the two vectors
ret.x = Self.x + rhs.x
ret.y = Self.y + rhs.y

Return ret
End Function

See Also

+ operator, Operator_AddRight, Operator_And, Operator_Divide, Operator_IntegerDivide, Operator_Modulo, Operator_Multiply, Operator_Negate, Operator_Or, Operator_Power, Operator_Subtract, Operator Overloading