The following standard IDL operators work directly on object reference variables:

Attempting to use other standard operators on object references results in an error.

Tip: Beginning with IDL 8.0, it is possible to overload some IDL operators so that they invoke a user-defined method rather than performing their normal function. See Object Operator Overloading Overview for details.

Many non-computational functions and procedures in IDL also work with object references, such as SIZE, N_ELEMENTS, HELP, and PRINT.

Object Assignment


Assignment works in the expected manner—assigning an object reference to a variable gives you another variable with the same reference. Hence, after executing the statements:

;Define a class structure.
struct = { cname, data1:0.0 }
 
;Create an object.
A = OBJ_NEW('cname')
 
;Create a second object reference.
B = A
 
HELP, A, B

IDL prints:

A               OBJREF    = <ObjHeapVar1(CNAME)>
B               OBJREF    = <ObjHeapVar1(CNAME)>

Note that both A and B are references to the same object heap variable.

Note: The assignment operator cannot be overridden by a user-defined method.

Object Equality and Inequality


The EQ and NE operators allow you to compare object references to see if they refer to the same object heap variable. For example:

;Define a class structure.
struct = {cname, data:0.0}
 
;Create an object.
A = OBJ_NEW('CNAME')
 
;B refers to the same object as A.
B = A
 
;C contains a null object reference.
C = OBJ_NEW()
 
PRINT, 'A EQ B: ', A EQ B & $
PRINT, 'A NE B: ', A NE B & $
PRINT, 'A EQ C: ', A EQ C & $
PRINT, 'C EQ NULL: ', C EQ OBJ_NEW() & $
PRINT, 'C NE NULL:', C NE OBJ_NEW()

IDL prints:

A EQ B:    1
A NE B:    0
A EQ C:    0
C EQ NULL: 1
C NE NULL: 0
 

Note: The EQ and NE operators can be overridden by user-defined methods. See Object Operator Overloading Overview for details.