小编Inf*_*kin的帖子

在GCC上自动声明映射迭代器错误

我的地图定义为:

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)

我只是无法理解这一点,我不明白为什么我的代码不起作用.我感谢任何帮助.

c++ gcc auto c++11 c++17

3
推荐指数
1
解决办法
121
查看次数

标签 统计

auto ×1

c++ ×1

c++11 ×1

c++17 ×1

gcc ×1