Method

# Operator_Subtract

<div class="rst-class">

forsearch

</div>

Operator

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

## Description

Used to overload the `-</api/language/operators/mathematical/->` operator when used for subtraction, providing custom functionality.

## Notes

Create an <span class="title-ref">Operator_Subtract</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 the left operand and the other operand is passed as a parameter.

## Sample code

Suppose you have a class, Vector, that can store a vector. To define the `-</api/language/operators/mathematical/->` operator for this class, create a method of the Vector class called <span class="title-ref">Operator_Subtract</span>.

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

Operator_Subtract is defined as:

``` xojo
Function Operator_Subtract(rhs As Vector) As Vector
  ' rhs stands for right-hand-side, the vector to be subtracted from Self
  Var ret As New Vector ' the difference between 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 SubtractRight</api/language/operators/operator_overloads/operator_subtractright>` function.

</div>
