=的重载问题
重载失败,要写成两个等于号,才赋值成功#include <iostream.h>
class A
{
public:
A operator =(int x)
{
A aa;
aa.a=x;
return aa;
}
void show()
{
cout<<a<<endl;
}
private:
int a;
};
void main()
{
A a1;
a1=3; //这里要写a1=a1=3;才能赋值成功。怎样改可以直接a1=3 ?
a1.show();
}