Operator_Subtract

From Xojo Documentation

Revision as of 14:49, 3 August 2021 by Gperlman (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
You are currently browsing the old Xojo documentation site. Please visit the new Xojo documentation site!
Global Method

Operator_Subtract(rightHandSide As Type)

Supported for all project types and targets.

Used to overload the - operator when used for subtraction, providing custom functionality.


Global Method

Operator_Subtract() As Type

Supported for all project types and targets.

Used to overload the - operator when used for subtraction, providing custom functionality.

Notes

Create an Operator_Subtract function in a class to specify the functionality of the - operator for that class.

In the function, the Self 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 - operator for this class, create a method of the Vector class called Operator_Subtract.

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

Operator_Subtract is defined as:

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

See Also

- operator, Operator_SubtractRight function.