/* Test the calling of the destroy method as well as illustrating * the difference between subtraction and negation in operator * overloading */ using namespace oadl; class complex { public var real, imag; public proc create(r, i) { real = r; imag = i; say("Creating (", r, ",", i, ")\n"); } operator + (rhs) { var result; result = new complex(real + rhs.real, imag + rhs.imag); return result; } operator - (rhs) { var result; result = new complex(real - rhs.real, imag - rhs.imag); return result; } operator !- (rhs) { var result; result = new complex(-real, -imag); return result; } public proc destroy() { say("Destroying (", real, ",", imag, ")\n"); } } proc main() { var a = complex(1,2); var b = complex(3,4); var c; c = a + b; say("c = {", c.real, ",", c.imag, "}\n"); c = a - b; say("c = {", c.real, ",", c.imag, "}\n"); c = -a; say("c = {", c.real, ",", c.imag, "}\n"); c = nil; gc(); }