我在将一些value_pairs插入地图时遇到了麻烦.这是基本的想法.
// private
typedef Foo* (*Bar)( const std::string &x, int y );
typedef std::map<std::string, Bar> myMap;
template<class T>
Foo* DoThing( const std::string &x, int y ) {
return new T( x, y );
}
myMap m_map;
// some map insertion code
m_map.insert( myMap::value_type( "blah", &DoThing<SomeType> ));
m_map.insert( myMap::value_type( "blech", &DoThing<OtherType> ));
Run Code Online (Sandbox Code Playgroud)
这会给编译器错误说no matching function call to std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, Foo* (*)(const std::string&, int)>::pair(const char [5], <unresolved overloaded function type>)不确定我在语法上做错了什么,或者为什么我得到了unresolved overloaded function type.我最好的猜测是,它不知道DoThing返回a …