I have a map which maps a pair of two classes to a simple string. "FirstCollection" and "SecondCollection" are classes, "myCollecttion" is an object of one of them. But when iterating over the map I'm getting a compile error:

error: no match for call to '(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());
    }

Error in this line: parent->setName(iter->second());

Any suggestions?

有帮助吗?

解决方案

iter->second is a member variable not a function. Remove the parentheses: parent->setName(iter->second);.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top