请问这段代码哪里错误了?(关于重载operator<<)

lbeast 2005-12-05 11:06:37
// -----1 Menu.h
#include <string>
#include <iostream>
#include <iomanip>

using namespace std; //记住 不要再忘了!!!

class MenuMember{

public:

int m_no;
string m_note,m_path;

MenuMember(int no = 1,string note = "初始化说明",string path = "初始化路径")
{
m_no = no;
m_note = note;
m_path = path;
}

~MenuMember() { };

MenuMember& operator () (int no,string note,string path);

MenuMember& operator += (const MenuMember &);

friend ostream& operator << (ostream&,const MenuMember&);

private:

};

ostream& operator << (ostream &out,const MenuMember &M)
{
out << M.m_note ;
return out;
}


// ----2 Menu.cpp
#pragma warning(disable: 4786)

#include <vector>
#include <algorithm>
#include "Menu.h"

int main()
{

MenuMember Mm1,Mm2;

cout << Mm1;

return 0;

}

谢谢各位!
...全文
102 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
darwin001 2005-12-05
  • 打赏
  • 举报
回复
请问楼上:Vc6的被丁在何处下载的?
dx30611 2005-12-05
  • 打赏
  • 举报
回复
我在.net下编译能运行的
是编译器的问题
lbeast 2005-12-05
  • 打赏
  • 举报
回复
OK 解决了
Vc6.0的问题
打了Vc的补丁就好了。
谢谢大家。
dragonzxh 2005-12-05
  • 打赏
  • 举报
回复
#include "stdafx.h"
#include <string>
#include <iostream>
#include <iomanip>

#include <vector>
#include <algorithm>

using namespace std; //¼Çס ²»ÒªÔÙÍüÁË£

class MenuMember;
ostream& operator << (ostream &out,const MenuMember &M);

class MenuMember
{
public:

int m_no;
string m_note,m_path;

MenuMember(int no = 1,string note = "³õʼ»¯ËµÃ÷",string path = "³õʼ»¯Â·¾¶")
{
m_no = no;
m_note = note;
m_path = path;
}

~MenuMember() { };

MenuMember& operator () (int no,string note,string path);

MenuMember& operator += (const MenuMember &);

friend ostream& operator << (ostream&,const MenuMember&);

private:

};

ostream& operator << (ostream &out,const MenuMember &M)
{
out << M.m_note ;
return out;
}



//#pragma warning(disable: 4786)


int main()
{
MenuMember Mm1,Mm2;
cout << Mm1;
system("pause");
return 0;
}
guyanhun 2005-12-05
  • 打赏
  • 举报
回复
没有问题的啊!
编译器的问题吧.
lbeast 2005-12-05
  • 打赏
  • 举报
回复
这里:

error C2593: 'operator <<' is ambiguous

wow不是想象中那么好玩錒。唉。
PMsg 2005-12-05
  • 打赏
  • 举报
回复
有什么问题?

64,282

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧