各位帮我看一下这段C++代码的错误
class Channel
{
public:
int list;
double hz;
string name;
Channel(int a=0,double b=0.0,string c=" ");
friend ostream &operator<<(ostream &output,Channel &ob);
};
ostream &operator<<(ostream &output,Channel &ob)
{
output<<"( "<<ob.name<<" ";
output<<ob.list<<" ";
output<<ob.hz<<" "<<" )\n";
return output;
}
重载<<之后,
输出cout<<p->m_element<<endl;
p->m_element是Channel类型
提示错误error C2593: 'operator <<' is ambiguous
我以前编译是正确的,
过了一段时间编译怎么是错误的??
谢谢!!!!
问题点数:0、回复次数:3Top
1 楼nasi00(莫傲·逍遥)回复于 2005-06-02 02:20:32 得分 0
我这么改了一下,现在在VC6下面是OK的:
#include <iostream>
#include <string>
class Channel
{
public:
int list;
double hz;
std::string name;
Channel()
{
list=0;
hz=1.0;
name="hello, world";
}
friend std::ostream &operator<<(std::ostream &output,Channel &ob);
};
std::ostream &operator<<(std::ostream &output,Channel &ob)
{
output<<"( "<<ob.name<<" ";
output<<ob.list<<" ";
output<<ob.hz<<" "<<" )\n";
return output;
}
int main()
{
Channel a;
std::cout << a << std::endl;
return 0;
}Top
2 楼chbtime()回复于 2005-06-02 13:29:35 得分 0
thank you!!!Top
3 楼xuzheng318(忧郁王子)回复于 2005-06-02 13:31:43 得分 0
std::ostream &operator<<(std::ostream &output,Channel &ob)
{
output<<"( "<<ob.name<<" ";
output<<ob.list<<" ";
output<<ob.hz<<" "<<" )\n";
return output;
}
Top




