1
我正在尝试使用超载概念来将3个对象等同起来c1
,c2
,c3
。 但它给我一个错误OVERLOADING OPERATORS =错误
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 = ,然后C3 = C2,但如何将编译器,重载的操作符定义进行比较?
我会添加提及采用'const const''也是。 – 2012-07-13 08:16:22
他甚至如何访问类变量?他们被设置为私人... – 2012-07-13 08:18:35
@ArmenTsirunyan你的讽刺话不会帮助任何人。如果你注意到,我正在谈论他通过的课程。 – 2012-07-13 08:23:01