我正在尝试使用重载概念来等同于 3 个对象c1
, c2
, c3
. 但这给了我一个错误
error: no match for 'operator=' in 'c3 = c2. circle::operator=(((circle&)(& c1)))'
是什么原因造成的,怎么改??
#include<iostream>
using namespace std;
class circle
{
private:
int radius;
float x,y;
public:
circle()
{}
circle(int rr,float xx,float yy)
{
radius=rr;
x=xx;
y=yy;
}
circle& operator=(const circle& c)
{
cout<<endl<<"assignment operator invoked";
radius=c.radius;
x=c.x;
y=c.y;
return *this;
}
void showdata()
{
cout<<endl<<"\n radius="<<radius;
cout<<endl<<"x coordinate="<<x;
cout<<endl<<"y coordinate="<<y<<endl;
}
};
int main()
{
circle c1 (10,2.5,2.5);
circle c2,c3;
c3=c2=c1;
c1.showdata();
c2.showdata();
c3.showdata();
return 0;
}
所以这个重载的运算符将被调用两次。首先是 c2=c1,然后是 c3=c2 但是编译器如何将它与重载的运算符定义进行比较?