stl map 遍历出错

CpRcF 2008-04-21 02:30:07


map<string,IObject> objMap; //IObject 是一个自己定义的类

objMap.insert(....);
objMap.insert(....);
objMap.insert(....);

map<string,IObject>::const_iterator mapIt = objMap.begin();
for(;mapIt != objMap.end(); mapIt++) {
cout<<mapIt->first()<<","<<mapIt->second()<<endl;//这里报错
}




出错信息:

no match for call to `(const std::string) ()'
no match for call to `(const _MMSeg_CPP_::Word) ()'

请问如何修改?
...全文
246 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
yangch_nhcmo 2008-04-21
  • 打赏
  • 举报
回复
3楼正解!
CpRcF 2008-04-21
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 mscf 的回复:]
就算能运行成功,不知道这样的代码准备干啥

C/C++ codemap<string,IObject>::const_iterator mapIt = objMap.begin();
for(;mapIt != objMap.end(); mapIt++) {
cout<<mapIt->first()<<","<<mapIt->second()<<endl;//这里报错
}
[/Quote]

实现了<<重载

呵呵,我这么写只是想知道 为什么会报那样的错,,,
当然有别的用途
薛定谔之死猫 2008-04-21
  • 打赏
  • 举报
回复
就算能运行成功,不知道这样的代码准备干啥
map<string,IObject>::const_iterator mapIt = objMap.begin();
for(;mapIt != objMap.end(); mapIt++) {
cout<<mapIt->first()<<","<<mapIt->second()<<endl;//这里报错
}
薛定谔之死猫 2008-04-21
  • 打赏
  • 举报
回复
IObject实现<<友元操作符重载没?
con_con 2008-04-21
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 akirya 的回复:]
first和second都是成员变量,没()
cout < <mapIt->first < <"," < <mapIt->second < <endl;
[/Quote]

正在学习中
  • 打赏
  • 举报
回复
first和second都是成员变量,没()
cout<<mapIt->first<<","<<mapIt->second<<endl;
babyvox1999 2008-04-21
  • 打赏
  • 举报
回复
没有重载<< ??
CpRcF 2008-04-21
  • 打赏
  • 举报
回复
出错信息:

no match for call to `(const std::string) ()'
no match for call to `(const IObject) ()'

64,637

社区成员

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

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