作者dragonegg (egg)
站內EE_DSnP
標題[問題] cmdParser.cpp 的 CmdParser::printHelp() function
時間Thu Apr 10 23:48:01 2008
我在function裡頭是這樣子打的:
72 // TODO...
73 CmdMap::iterator it ;
74 for( it= _cmdMap.begin() ; it != _cmdMap.end() ;++it)
75 cout << (*it).second->help() << endl ;
76
77 cout << endl;
但在compile時出現下面的問題:
cmdParser.cpp:74: error: no match for 'operator=' in 'it = (((const
std::map<const std::string, CmdExec*, std::less<const std::string>,
std::allocator<std::pair<const std::string, CmdExec*> > >*)((const
CmdParser*)this)) + 5424u)->std::map<_Key, _Tp, _Compare, _Alloc>::begin
[with _Key = const std::string, _Tp = CmdExec*, _Compare = std::less<const
std::string>, _Alloc = std::allocator<std::pair<const std::string, CmdExec*>
>]()'
/usr/lib/gcc/i386-redhat-linux/3.4.4/../../../../include/c++/3.4.4/bits/stl_tree.h:152:
note: candidates are: std::_Rb_tree_iterator<std::pair<const std::string,
CmdExec*> >& std::_Rb_tree_iterator<std::pair<const std::string, CmdExec*>
>::operator=(const std::_Rb_tree_iterator<std::pair<const std::string,
CmdExec*> >&)
.....(以下省略…Orz)
不知道為什麼會有這個error? 可否請大家幫忙看看… 累死了Orz...
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 118.166.197.152
1F:推 ric2k1:Good question. Const member function => object is const 04/10 23:48
2F:→ ric2k1:=> its data member (including static) is const 04/10 23:49
3F:→ ric2k1:=> Please use "const_iterator" 04/10 23:49
4F:推 battlecruise:阿 也順便解答我的問題 謝謝! 04/11 13:00
5F:推 GriffeyKao:喔 我也有遇到這個問題耶 謝啦!! 04/11 16:03
6F:推 GriffeyKao:嗯 同學(是健達嗎?)這行怪怪的跟你說一下 04/11 16:07
7F:→ GriffeyKao:cout << (*it).second->help() << endl 04/11 16:08
8F:→ GriffeyKao:應該只要用pointer去呼叫hepl()就行了吧 我覺得是這樣 04/11 16:09
9F:→ dragonegg:哦對是我耍笨了= = 04/11 17:58