我有以下课程,我与它交了朋友cout
现在我正在尝试与它交朋友cin
但我收到错误...任何人都可以帮助我,或者告诉我我做错了什么吗?
error:
c:\mingw\bin../lib/gcc/mingw32/4.6.1/include/c++/bits/stl_algo.h:2215:4:错误:将“const RANgle”作为“int RANgle”的“this”参数传递: :operator
class RAngle
:
class RAngle
{
private:
int *x,*y,*l;
public:
int solution,prec;
RAngle(){
this->x = 0;
this->y = 0;
this->l = 0;
}
RAngle(int i,int j,int k){
this->x = &i;
this->y = &j;
this->l = &k;
}
friend istream& operator >>( istream& is, RAngle &ra)
{
is >> ra->x;
is >> ra->y;
is >> ra->l;
return is ;
}
}
没有足够的代码来回答您的问题。但从错误中我会说你,你的int RAngle::operator<(RAngle)
没有定义为 const 方法,并且您在只有 const 的地方使用它。
另外,这不是很好的做法operator<
或其他比较运算符返回 int,因为这可能会导致误解。这样的运算符应该返回bool
.
所以,会有这样的事情bool RAngle::operator<(const RAngle& other) const { /*...*/ }
。这个话题已经涵盖了here https://stackoverflow.com/questions/4421706/operator-overloading and here http://en.wikipedia.org/wiki/Operators_in_C_and_C++.
Update这段代码完全奇怪。为什么使用指针int
?为什么要将某些数据设为私有?构造函数RAngle(int i,int j,int k)
不会像你想象的那样工作。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)