c++ - 错误 : no match for call to '(const std::basic_string<char>) ()'

标签 c++ c++11 map stdstring

我有一个映射,它将一对两个类映射到一个简单的字符串。 “FirstCollection”和“SecondCollection”是类,“myCollection”是其中一个的对象。 但是在遍历 map 时出现编译错误:

错误:对“(const std::basic_string) ()”的调用不匹配

typedef std::map <
    std::pair < Collection, Envelope::Envelope >
  , std::string > NameMap;

NameMap globalNameMap = map_list_of
        ( std::make_pair ( FirstCollection, Envelope::A ), "Something")
        ( std::make_pair ( SecondCollection, Envelope::B ), "Another thing")


    NameMap::const_iterator iter
            = globalNameMap.find( std::make_pair ( myCollection, myEnvelope ));

    if ( iter == globalNameMap.end() )
    {
          parent->setName("anything");
    } else {
          parent->setName(iter->second());
    }

这一行错误:parent->setName(iter->second());

有什么建议吗?

最佳答案

iter->second 是成员变量而不是函数。去掉括号:parent->setName(iter->second);

关于c++ - 错误 : no match for call to '(const std::basic_string<char>) ()' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23082849/

相关文章:

java - 是否有接受各种数据类型值的字典?

c++ - 为什么我必须释放二维数组两次以避免内存泄漏?

c++ - 有什么办法可以将这个函数分开并插入空格吗?

c++ - 从 begin() 迭代到 end() 时,STL 映射是否总是给出相同的顺序?

C++右值引用行为(具体示例)

c++ - C++ 中 f(g(), h()) 的求值顺序

c++ - STL 映射运算符 [] 不好吗?

c++ - log4cxx::Level::getError() 是否泄漏内存?

c++ - GDB:仅当先前的中断在 func2 上时才在 func1 上中断

c++ - put_money 是按值还是按引用保存其参数?