将项目插入到std :: map时错误
Error while inserting item to std::map
我试图将新项目插入具有自定义键和值类型的地图:
struct Address {
bool operator<(const Address& a) const { return 1; }
};
struct Cell {};
std::map<Address, Cell> map;
map.insert(std::make_pair<Address, Cell>(Address(), Cell()));
g 编译恰好编译,但我的IDE(CLION(抱怨插入方法的参数(将其标记为红色下划线的错误(:参数类型不匹配:class'STD :: pair&lt; pair&lt;地址,cell&gt;'与类'std :: prinitizer_list&lt&lt :: map&lt; main :: main :: main :: cell&gt; :: value_types&gt;'
不兼容。为什么我会遇到此错误?我的代码有问题吗?还是IDE中的错误?
您可以使用std :: vector而不是std :: map width a std :: pair。
解决问题更改:
std::map<Address, Cell> map;
to:
std::vector<std::pair<Address, Cell> > map;
并包括矢量库
#include <vector>
相关文章:
- C++将参数包传递给std::map导致错误C3245
- c++:[错误]"map"之前的预期初始值设定项
- 编译器错误 C2664 使用 std::map 和自定义类作为其值
- std::map 擦除 - 将迭代器传递给错误的映射
- 带有 std::map 的模板函数给出错误:变量或字段声明为 void
- 尝试 ptr->map.clear() 时出现分段错误
- 错误:与'operator='不匹配(操作数类型为"std::map<int、double>::iterator
- 使用std :: map时,包含unique_ptr的结构中的默认破坏者会导致编译错误
- 自动,错误:MAP ITERATOR没有名为“ First”的成员
- 将项目插入到std :: map时错误
- 由于从 std::map 派生的类中的 std::map 迭代器导致的内存错误
- 如何在<int>错误 C2338 中组织 map<set<multiset>,int> C++
- 在 std::map 中使用结构作为值时出现运行时错误
- map.insert:"Invalid arguments"错误与 pair<enum,vector<*>>
- SWIG:包装 std::map<key 时编译器错误,val *>
- 使用 std::map 时只读成员的错误递减
- 为什么缩小转换范围不能防止错误类型的map.insert()失败
- 错误 C2062:引用 std::map 时键入意外
- std::map错误的多重定义
- 带有指针的map:错误的值评估