ibm Rational Rhapsody 7.5 — Overloading Operators

Basic code generation concepts real = c.real; imag = c.imag; } Complex(double r, double i) // Convert constructor Arguments: double r double i = 0.0 Body: { real = r; imag = i; } operator-(Complex c) // Subtraction Return type: Complex Arguments: Complex c Body: { return Complex(real - c.real, imag - c.imag); } operator[](int index) // Array subscript Return type: Complex& Arguments: int index // dummy operator - only // for instrumentation // check Body: { return *this; } operator+(Complex& c) // Addition by value Return type: Complex Arguments: Complex& c Body: { return Complex(real + c.real,imag + c.imag); } operator+(Complex* c) // Addition by reference Return type: Complex* Arguments:

Complex *c Body: { cGlobal = new Complex (real + c->real, imag + c->imag); return cGlobal; } operator++() // Prefix increment Return type: Complex& Body: { real += 1.0; imag += 1.0; return *this; } operator=(Complex& c) // Assignment by value Return type: Complex& Arguments: Complex& c Body: { real = c.real, imag = c.imag; return *this; } 950 User Guide