我的地图定义为:
std::map<unsigned int, std::string> spCalls;
Run Code Online (Sandbox Code Playgroud)
我还有一个函数,在给定键的情况下返回字符串.它被定义为:
std::string spGetCallString(unsigned int key)
{
auto iter{ spCalls.find(key) };
return iter->second;
}
Run Code Online (Sandbox Code Playgroud)
当试图用GCC编译它时,我得到一个错误
error: base operand of '->' has non-pointer type
'std::initializer_list < std::_Rb_tree_iterator < std::pair < const unsigned int, std::basic_string < char> > > >'
return iter->second;"
Run Code Online (Sandbox Code Playgroud)
我只是无法理解这一点,我不明白为什么我的代码不起作用.我感谢任何帮助.