本文主要是介绍Effective 49 learn to deciper STL-related compiler diagnostics,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
cannot convert from ‘class std::_Tree<SOMETHING>::const_iterator’ to ‘class std::_Tree<SOMETHING>::iterator’
class NiftyEmailProgram {
private:typedef map<string, string> NicknameMap;NicknameMap nickname;
public:...void showEmailAddress(const string& nickname) const;
};void NiftyEmailProgram::showEmailAddress(const string& nickname) const {...NicknameMap::iterator i = nicknames.find(nickname); // error!if (i != nicknames.end())......}
nicknames is declared as a non-const map, but showEmailAddress is a const member funcion, and inside a const member function, all non-static data members of the class const! Inside showEmailAddress, nicknames is a const map. We are trying to generate an iterator into a map we have promised not to modify. To fix the problem, we must either make i a const_iterator or we must make showEmailAddress a non-const member function.
这篇关于Effective 49 learn to deciper STL-related compiler diagnostics的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!