【发布时间】:2020-05-18 15:23:13
【问题描述】:
我用
创建了一张地图std::map<long,std::vector<long> > indices
当尝试插入一个键和向量元素时
indices.insert(std::pair<long,std::vector<long> >(0,{0,1,2}));
我收到大量以
结尾的错误C:/TDM-GCC-64/lib/gcc/x86_64-w64-mingw32/5.1.0/include/c++/bits/stl_map.h:685:9: note: template argument deduction/substitution failed:
Main.cpp:44:66: note: candidate expects 2 arguments, 1 provided
indices.insert(std::pair<long,std::vector<long> > (0,{0,1,2}));
如果在编译期间我这样做了
g++ Main.cpp -std=c++17
但是它编译没有任何错误
g++ Main.cpp -std=c++11
c++17 中的过程是否不同?如果是,那是什么? 还是我错过了什么?
【问题讨论】:
-
您应该使用
std::pair<const long,std::vector<long> >。该对的第一个元素 (value_type) 是一个 const 对象。 -
如果我使用
-std=c++17编译仍然显示相同的错误 -
不知道我做错了什么,编译器错误?
-
可能是您发布的行上方的错误。这些位置并不总是准确的