Listing 10 operator+ and operator<< for a complex number data type
#include <iostream.h> struct complex { double real, imag; complex(double = 0.0, double = 0.0); }; complex::complex(double r, double i) { real = r; imag = i; } inline ostream& operator<<(ostream &os, const complex &c) { os << '(' << c.real << ',' << c,imag << ')'; return os; } inline complex operator+(const complex &c1, const complex &c2) { return complex(c1.real+c2.real,c1.imag+c2.imag); } /* End of File */