#include <iostream>
using namespace std;
class Complex
{
int real;
int img;
public:
Complex ()
{
real = 0;
img = 0;
}
Complex (int r, int i)
{
real = r;
img = i;
}
void Display ()
{
cout << real << "+i" << img;
}
Complex operator + (Complex c);
};
Complex Complex ::operator + (Complex c)
{
Complex temp;
temp.real = real + c.real;
temp.img = img + c.img;
return temp;
}
int main ()
{
Complex C1(5, 3), C2(10, 5), C3;
C1.Display();
cout << " + ";
C2.Display();
cout << " = ";
C3 = C1 + C2; //(or) C3=C1.operator+(C2);
C3.Display();
}
Note: Need to be arranged in compiler after copied
OutPut:
5+i3 + 10+i5 = 15+i8