没有匹配的成员函数可用于调用“插入”消息。 std :: unordered_map [英] No matching member function for call to "insert" std::unordered_map
本文介绍了没有匹配的成员函数可用于调用“插入”消息。 std :: unordered_map的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图将字符串
散列到指向指向字符串的无效函数的指针
。尝试将我的键值对插入到地图中时出现以下错误:
I am trying to hash a string
to a pointer to a void function which takes in a string
. I get the following error when trying to insert my key value pair into the map:
没有匹配的成员函数可以调用 insert
我不确定如何解释此错误。
I am not sure how to interpret this error.
我认为我是在传递错误
#include <string>
#include <unordered_map>
using namespace std;
void some_function(string arg)
{
//some code
}
int main(int argc, const char * argv[]) {
typedef void (*SwitchFunction)(string);
unordered_map<string, SwitchFunction> switch_map;
//trouble with this line
switch_map.insert("example arg", &some_function);
}
任何建议将不胜感激。
推荐答案
如果您查看 std :: unordered_map :: insert
,会看到这些:
If you look at the overloads for std::unordered_map::insert
, you'll see these:
std::pair<iterator,bool> insert( const value_type& value );
template< class P >
std::pair<iterator,bool> insert( P&& value );
std::pair<iterator,bool> insert( value_type&& value );
iterator insert( const_iterator hint, const value_type& value );
template< class P >
iterator insert( const_iterator hint, P&& value );
iterator insert( const_iterator hint, value_type&& value );
template< class InputIt >
void insert( InputIt first, InputIt last );
void insert( std::initializer_list<value_type> ilist );
没有 insert(key_type,mapping_type)
,这就是您要尝试做的。您的意思是:
There is no insert(key_type, mapped_type)
, which is what you're trying to do. What you meant was:
switch_map.insert(std::make_pair("example arg", &some_function));
这篇关于没有匹配的成员函数可用于调用“插入”消息。 std :: unordered_map的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文