Operator SubtractRight

From Xojo Documentation

Revision as of 19:11, 19 November 2009 by WikiSysop (talk) (1 revision)
(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!


Description

Used to overload the - operator, providing custom functionality. Operator_SubtractRight is the same as Operator_Subtract but the implicit Self instance is on the right instead of the left in the subtraction.


Notes

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

The ordinary (left) methods are always preferred; REALbasic uses the Right version only if there is no legal left version.


Examples

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_SubtractRight.

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


Operator_SubtractRight is defined as:

Function Operator_SubtractRight (lhs as Vector) as Vector
 //lhs stands for left-hand-side, the vector to be added to Self
Dim ret as New Vector //the difference between the two vectors
 ret.x=lhs.x + Self.x
 ret.y=lhs.y + Self.y


Return ret


See Also

- operator, Operator_Subtract function.