C++错误: map.insert(make_pair(struct, vector<struct>));
C++ error: map.insert(make_pair(struct, vector<struct>));
下面的代码是国际象棋游戏的一部分,其中键是棋子的位置,值是棋子具有的可能移动
#include<iostream>
#include<map>
#include<vector>
using namespace std;
struct Coordinate{
int x, y;
};
int main(){
map<Coordinate, vector<Coordinate>> moves;//map that have an struct as key and a vector of structs as value.
//There is the error
moves.insert(make_pair(Coordinate{0,0},//the struct
vector<Coordinate>{Coordinate{1,1},//the vector
Coordinate{2,2},
Coordinate{3,3}}));
return 0;
};
Thos代码将我带到文件"stl_function.h"中的第235行
您需要为结构提供一个自定义比较器:
struct Coordinate{
int x, y;
constexpr bool operator<(const Coordinate & rhs) const
{
return x < rhs.x && y < rhs.y;
}
};
相关文章:
- 附加使用 Struct 作为"multikey"并将 std::vector 用作映射值的映射
- 在c++Primer中使用Struct和Vector时出现错误C2661
- OCCI - setDataBuffer + vector<struct>
- C 如何推动vector struct的成员
- 使用 boost.python 公开 std::vector<struct>
- 使用Isringstream和struct/vector在给定的数据之间建立连接
- 当编译器看到 std::vector<Typo> 和 std::vector<struct 拼写错误时发出的诊断之间的差异背后的理由是什么>
- 使用 std::transform 将 std::vector<struct{key; val;}> 转换为 std::map<key, val>
- 将数据从struct二进制复制到std::vector
- 元素 std::vector <struct>的更有成效的段落
- Dynamic vector using Struct
- 3D Vector of struct emplace_back
- struct vs vector作为数据持有者
- C++错误: map.insert(make_pair(struct, vector<struct>));
- 为 std::vector <struct>创建一个 getter 函数
- 创建一个Struct,然后通过引用传递一个带有这些Struct的vector
- 带有==操作符的struct vector的上界
- Vector of struct (copy_n和归并排序)
- 将vector(在struct中定义时)传递给函数
- 在struct vector中初始化vector