//-------------------------------------------- // CLASSES : data structures. (2) //-------------------------------------------- #include //-------------------------------------------- // no need of destructors: // members are all public // use of overloading: // + is for float and complex numbers //-------------------------------------------- class complex {public : float re; float im; complex(float r, float i) : re(r), im(i) { }; // constructor }; complex operator + (complex a1, complex a2) {return complex(a1.re + a2.re, a1.im + a2.im);}; //-------------------------------------------- void main() { complex a (1.0, 4.0); complex b (3.0, 7.5); complex c = a + b; cout << "\n c = " << c.re << " + " << c.im << " i\n"; //------ defining a pointer to a class ------- complex * cp = &c; cout << "\n p.re = " << cp->re << "\n\n"; } //-------------------------------------------- // input: output: // // c is: 4 + 11.5 i // // p.re = 4 // //--------------------------------------------