读书人

gt;gt;重载警告解决方案

发布时间: 2012-03-04 11:13:33 作者: rapoo

>>重载警告
类原型:
class fushu
{
double x,y;
public:
……
friend istream& operator> > (istream&os,const fushu&a);
};
当有下列定义时有警告
istream& operator> > (istream&is,const fushu&a)
{
is> > a.x;
is> > a.y;
return is;
}
'operator> > ' : recursive on all control paths, function will cause runtime stack overflow
运行时无法输入就跳过了

[解决办法]
friend istream& operator> > (istream&os,const fushu&a);
==========
friend istream& operator> > (istream&os,fushu&a);

istream& operator> > (istream&is,const fushu&a)
=========
istream& operator> > (istream&is,fushu&a)
[解决办法]
呵呵...楼主想输入数据为什么还要把参数定为const呢?
[解决办法]
把两个const去掉.
[解决办法]
这个警告真是这段代码引起得?虽然const有错,但是也不该导致这种错误啊?
[解决办法]
呃,只看了错误信息就发表意见了,错误意见....
刚刚完整看了下,> > 应该被已经重载了
应该不会出现这个问题

应该只有const的问题

读书人网 >C++

热点推荐