//赋值运算符重载
#include<iostream>
using namespace std;
class complex
{
private:
int real;
int imag;
public:
complex(int r=0, int i=0)//构造函数
{
real = r;
imag = i;
}
void Print()//输出函数
{
cout << "real=" << real << " " << "imag=" << imag;
}
complex& operator=(const complex& rhs);//赋值运算符重载(声明)
};
complex& complex:: operator=(const complex& rhs)//类外定义
{
this->real = rhs.real;
this->imag = rhs.imag;
return *this;
}
int main()
{
complex a(1,2),b(3,4),c;
a = b;
a.Print();
puts("");
b.operator=(c);
c.Print();
}