把operator>>那里的右操作数CPoint &p前面的const去掉就通过了编译,大概是因为重载输入运算符会改变p,所以不能加上const。
我在C++中实现了这样一个类,但是在重载输入运算符那里提示错误:
cannot bind ‘std::istream {aka std::basic_istream}’ lvalue to ‘std::basic_istream&&’
有大佬能解释一下吗?我看了一些英文解答没太看懂。。
谢谢!
class CPoint{
private:
double x,y;
public:
CPoint():x(0),y(0){}
CPoint(double _x,double _y):x(_x),y(_y){}
friend ostream& operator<<(ostream& out,const CPoint &p)
{
out<<"("<<p.x<<","<<p.y<<")";
return out;
}
__**friend istream& operator>>(istream& stream,const CPoint &p){
stream>>p.x>>p.y;
return stream;
}__**
int operator>(const CPoint &p)
{
return sqrt(x*x+y*y)>sqrt(p.x*p.x+p.y*p.y);
}
};