Overloading Operators operator=(Complex* c) // Assignment by reference Return type: Complex* Arguments: Complex *c Body: { real = c->real; imag = c->imag; return this; } The following are some examples of code generated for these overloaded operators. This is the code generated for the overloaded prefix increment operator: Complex& Complex::operator++() { NOTIFY_OPERATION(operator++, operator++(), 0, operator_SERIALIZE); //#[ operation operator++() real += 1.0; imag += 1.0; return *this; //#] }; This is the code generated for the overloaded + operator:
Complex Complex::operator+(Complex& c) { NOTIFY_OPERATION(operator+, operator+(Complex&), 1, OM_operator_1_SERIALIZE); //#[ operation operator+(Complex&) return Complex(real + c.real, imag + c.imag); //#] }; This is the code generated for the first overloaded assignment operator: Complex& Complex::operator=(Complex& c) { NOTIFY_OPERATION(operator=, operator=(Complex&), 1, OM_operator_2_SERIALIZE); //#[ operation operator=(Complex&) real = c.real; imag = c.imag; return *this; //#] }; The browser lists the MainClass , which is a composite that instantiates three Complex classes. Its attributes are as follows:
Complex* c1 Complex* c2 Complex* c3 Body ~MainClass() //Destructor Body { delete c1; delete c2; delete c3; Rational Rhapsody 951