unordered_map,没有匹配函数调用错误
unordered_map, no match function call error
当我在Linux终端中运行使用c++11 or c++17
时,unordered_map
的示例程序运行良好。我在 eclipse
Neon.1a Release(4.6.1)
中使用 c++11 or c++17
尝试了相同的程序,给出了许多错误消息,包括
no matching function for call to ‘boost::unordered::unordered_map >::insert(int, std::pair)’
refmap.insert(1, std::make_pair(2,5));
#include <iostream>
#include <boost/unordered_map.hpp>
#include <utility>
typedef boost::unordered_map<int, std::pair<int, int> > reference_map;
reference_map refmap;
int main(){
refmap.insert(1, std::make_pair(2,5));
return 0;
}
insert
接受一个参数,而不是两个 - 一个 std::pair<K const, V>
(又名 std::unordered_map<K,V>::value_type
):
int main() {
refmap.insert(std::make_pair(1, std::make_pair(2, 5)));
}
为键和值采用单独参数的函数命名为 emplace
,在大多数情况下应首选:
int main() {
refmap.emplace(1, std::make_pair(2, 5));
}
当我在Linux终端中运行使用c++11 or c++17
时,unordered_map
的示例程序运行良好。我在 eclipse
Neon.1a Release(4.6.1)
中使用 c++11 or c++17
尝试了相同的程序,给出了许多错误消息,包括
no matching function for call to ‘boost::unordered::unordered_map >::insert(int, std::pair)’ refmap.insert(1, std::make_pair(2,5));
#include <iostream>
#include <boost/unordered_map.hpp>
#include <utility>
typedef boost::unordered_map<int, std::pair<int, int> > reference_map;
reference_map refmap;
int main(){
refmap.insert(1, std::make_pair(2,5));
return 0;
}
insert
接受一个参数,而不是两个 - 一个 std::pair<K const, V>
(又名 std::unordered_map<K,V>::value_type
):
int main() {
refmap.insert(std::make_pair(1, std::make_pair(2, 5)));
}
为键和值采用单独参数的函数命名为 emplace
,在大多数情况下应首选:
int main() {
refmap.emplace(1, std::make_pair(2, 5));
}