xHarbour Reference Documentation > Statement Reference |
Overloads an operator and declares a method to be invoked for it.
OPERATOR <cOperator> [ARG <operand>] INLINE <expression>
The OPERATOR statement can only be used in the class declaration between CLASS and ENDCLASS. It is the inline version of the METHOD...OPERATOR statement.
Note: only regular operators can be used for <cOperator>. Special operators are not supported. when <cOperator> is a binary operator, the object must be the left operand for <expression> being executed.
See also: | METHOD...OPERATOR |
Category: | Class declaration , Declaration , xHarbour extensions |
Header: | hbclass.ch |
Source: | vm\classes.c |
LIB: | xhb.lib |
DLL: | xhbdll.dll |
// The example declares a String class and displays the // results of operations with a String object. #include "HbClass.ch" PROCEDURE Main LOCAL obj := String():New( "Hello " ) ? obj = "Hello" // result: .T. ? obj == "Hello" // result: .F. ? obj != "Hello" // result: .F. ? obj <> "Hello" // result: .F. ? obj # "Hello" // result: .F. ? obj $ "Hello" // result: .F. ? obj < "hello" // result: .T. ? obj <= "hello" // result: .T. ? obj > "hello" // result: .F. ? obj >= "hello" // result: .F. ? obj + "World" // result: Hello World ? obj - "World" // result: HelloWorld RETURN CLASS String EXPORTED: DATA value INIT "" METHOD init( c ) INLINE ( IIf(valtype(c)=="C", ::value := c, ), self ) OPERATOR "=" ARG c INLINE ::value = c OPERATOR "==" ARG c INLINE ::value == c OPERATOR "!=" ARG c INLINE ::value != c OPERATOR "<" ARG c INLINE ::value < c OPERATOR "<=" ARG c INLINE ::value <= c OPERATOR ">" ARG c INLINE ::value > c OPERATOR ">=" ARG c INLINE ::value >= c OPERATOR "+" ARG c INLINE ::value + c OPERATOR "-" ARG c INLINE ::value - c OPERATOR "$" ARG c INLINE ::value $ c ENDCLASS
http://www.xHarbour.com