64,683
社区成员
发帖
与我相关
我的任务
分享
(a=b)=c中,a=b是把b赋值给a,返回a自身,整个式子是这样的:
a=b;
a=c;
A& A::operator = (const A &a)
{
if (this !=&a )
{
x = a.x ;
y = a.y ;
}
return *this ;
}
#include <iostream>
using namespace std;
class A
{
public:
A(int a,int b)
{
x = a ;
y = b ;
}
A& operator = (const A &a) ;//
public:
int x ;
int y ;
};
A& A::operator = (const A &a)
{
if ( this !=&a )
{
x = a.x ;
y = a.y ;
}
return *this ;
}
int main()
{
A b(3,4),c(5,6);
static A a(1,2);
(a=b)=c;
cout<<a.x<<endl;
cout<<a.y<<endl;
return 0;
}