#include<iostream>
using namespace std;
class Complex
{
int real, img;
public:
Complex(int r, int i)
{
real = r;
img = i;
}
void operator=(Complex& C)
{
real = C.real;
img = C.img;
}
void print()
{
cout << real << "+i" << img << endl;
}
};
int main()
{
Complex C1(2, 3), C2(4, 6);
cout << "BEFORE OVERLOADING ASSIGNMENTOPERATOR"<< endl;
cout << "C1 complex number: ";
C1.print();
cout << "C2 complex number: ";
C2.print();
C1 = C2;
cout << "AFTER OVERLOADING ASSIGNMENT OPERATOR"<< endl;
cout << "C1 complex number: ";
C1.print();
cout << "C2 complex number: ";
C2.print();
return 0;
}
Note: Need to be arranged in compiler after copied
OutPut:
BEFORE OVERLOADING ASSIGNMENT OPERATOR
C1 complex number: 2+i3
C2 complex number: 4+i6
AFTER OVERLOADING ASSIGNMENT OPERATOR
C1 complex number: 4+i6
C2 complex number: 4+i6
C1 complex number: 2+i3
C2 complex number: 4+i6
AFTER OVERLOADING ASSIGNMENT OPERATOR
C1 complex number: 4+i6
C2 complex number: 4+i6