Method

# Operator_Add

<div class="rst-class">

forsearch

</div>

Operator

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

## Description

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

## Notes

Create an <span class="title-ref">Operator_Add</span> function in a class to specify the functionality of the `+</api/language/operators/mathematical/+>` operator for that class.

In the function, the `Self</api/language/self_keyword>` instance is one of the operands and the other operand is passed as a parameter. <span class="title-ref">Operator_Add</span> assumes the `Self</api/language/self_keyword>` 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 `+</api/language/operators/mathematical/+>` operator for this class, create a method of the Vector class called <span class="title-ref">Operator_Add</span>.

The Vector class has two `Integer</api/data_types/integer>` properties, x and y.

Operator_Add is defined as:

``` xojo
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
```

## Compatibility

|                       |     |
|-----------------------|-----|
| **Project Types**     | All |
| **Operating Systems** | All |

<div class="seealso">

`+</api/language/operators/mathematical/+>` operator, `Operator AddRight</api/language/operators/operator_overloads/operator_addright>`, `Operator And</api/language/operators/operator_overloads/operator_and>`, `Operator Divide</api/language/operators/operator_overloads/operator_divide>`, `Operator IntegerDivide</api/language/operators/operator_overloads/operator_integerdivide>`, `Operator Modulo</api/language/operators/operator_overloads/operator_modulo>`, `Operator Multiply</api/language/operators/operator_overloads/operator_multiply>`, `Operator Negate</api/language/operators/operator_overloads/operator_negate>`, `Operator Or</api/language/operators/operator_overloads/operator_or>`, `Operator Power</api/language/operators/operator_overloads/operator_power>`, `Operator Subtract</api/language/operators/operator_overloads/operator_subtract>`, `Operator Overloading</api/language/operators/operator_overloads/operator_overloading>`

</div>
