>>运算符重载由于使用std名字空间所引起的问题
见程序如下:
#include <iostream>
using namespace std;
class HighWay
{
public:
short color;
short to;
short from;
friend istream& operator >> (istream&, HighWay&);
};
istream& operator >> (istream& io,HighWay& hw)
{
io >> hw.from;
io >> hw.to;
io >> hw.color;
return io;
}
int main()
{
int N,C,H;
cin >> N >> C >> H;
HighWay hw;
cin >> hw;
}
这样做在vc6会产生一个error C2593: 'operator >>' is ambiguous错误。
若去除using namespace std; 改为#include <iostream.h>就好了
难道c++中是先考虑名字空间再考虑运算符重载的吗?请高手指点