[NAME] ALL.dao.class.operator [TITLE] Operator Overloading [DESCRIPTION] Class instances can be used in operations in a way similar to those of built-in types, i f the classes define methods to overload relevant operators. Basic arithmetic operators are also supported for overloading. For example, addition oper ator can be supported for a class by defining a operator+ method in the following class, 1 class Integer 2 { 3 var value = 0 4 5 routine Integer( val = 0 ){ value = val } 6 7 static operator +( A : Integer, B : Integer ){ 8 io.writeln( 'Integer + Integer' ); 9 return Integer( A.value + B.value ); 10 } 11 } 12 var I1 = Integer( 123 ) 13 var I2 = Integer( 456 ) 14 var I3 = I1 + I2 Operation for accessing member fields can also be redefined as overloaded operator operat or .field_name and operator .field_name=: 1 class Integer 2 { 3 private 4 var value = 0 5 6 public 7 routine Integer( val = 0 ){ value = val } 8 9 operator .value(){ io.writeln( 'get value' ) } 10 operator .value=( v : int ){ value = v; io.writeln( 'get value' ) } 11 } 12 var I = Integer( 123 ) 13 var v = I.value 14 I.value = 456 Some classes may behavior like containers and have members that can be accessed using an index or a key. To support member accessing using an index or key, such class can overloa d operator [] and []= 1 class IntList 2 { 3 var ints = {} 4 5 routine Append( value : int ){ ints.append( value ) } 6 operator []( index : int ){ return ints[index] } 7 operator []=( value :int, index : int ){ ints[index] = value } 8 } 9 var ilist = IntList() 10 ilist.Append( 123 ) 11 ilist.Append( 456 ) 12 ilist[0] = 789 13 io.writeln( ilist[0] ) TODO: cast