c++中出现 error C2593: 'operator >>' is ambiguous 的原因?
程序如下:#include<iostream>#include<stdlib.h>usingnamespacestd;classpoint{public:inta,b;p...
程序如下:
#include<iostream>
#include<stdlib.h>
using namespace std;
class point
{
public:
int a,b;
point(int aa,int bb){a=aa;b=bb;}
friend istream &operator >> (istream &input,point ob);
friend ostream &operator << (ostream &stream,point ob);
};
istream &operator>>(istream &input,point& ob)
{
input>>ob.a>>ob.b;
return input;
}
ostream &operator<<(ostream &stream,point& ob)
{
stream<<ob.a<<' '<<ob.b<<endl;
return stream;
}
int main()
{
point p(2,5);
cin>>p;
cout<<p;
return 0;
} 展开
#include<iostream>
#include<stdlib.h>
using namespace std;
class point
{
public:
int a,b;
point(int aa,int bb){a=aa;b=bb;}
friend istream &operator >> (istream &input,point ob);
friend ostream &operator << (ostream &stream,point ob);
};
istream &operator>>(istream &input,point& ob)
{
input>>ob.a>>ob.b;
return input;
}
ostream &operator<<(ostream &stream,point& ob)
{
stream<<ob.a<<' '<<ob.b<<endl;
return stream;
}
int main()
{
point p(2,5);
cin>>p;
cout<<p;
return 0;
} 展开
1个回答
展开全部
意思很明确啊 >>操作符产生了二义性
更多追问追答
追问
怎么改?
追答
#include<iostream>
#include<stdlib.h>
using namespace std;
class point;
istream &operator >> (istream &input,point &ob);
ostream &operator << (ostream &stream,point &ob);
class point
{
public:
int a,b;
point(int aa,int bb){a=aa;b=bb;}
friend istream &operator >> (istream &input,point &ob);
friend ostream &operator << (ostream &stream,point &ob);
};
istream &operator>>(istream &input,point& ob)
{
input>>ob.a>>ob.b;
return input;
}
ostream &operator<<(ostream &stream,const point& ob)
{
stream<<ob.a<<' '<<ob.b<<endl;
return stream;
}
int main()
{
point p(2,5);
cin>>p;
cout<<p;
return 0;
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询