c++ - 二进制表达式的无效操作数('const pos_in_grid' 和 'const pos_in_grid')
问题描述
#include<iostream>
#include<string>
#include<sstream>
#include<fstream>
#include<vector>
#include<map>
#include<cstdlib>
#include<ctime>
using namespace std;
int vertices = 5;
int grid_x = 5;
int grid_y = 5;
struct pos_in_grid
{
int x_coordinate;
int y_coordinate;
};
map<pos_in_grid,int> grid_with_placement;
int initial_placement();
int main()
{
srand(time(NULL));
initial_placement();
return 0;
}
int initial_placement()
{
for(int i = 1;i<=vertices;)
{
pos_in_grid pos_of_node;
int j = rand()%grid_x;
pos_of_node.x_coordinate = j;
j = rand()%grid_y;
pos_of_node.y_coordinate = j;
if(grid_with_placement.find(pos_of_node) == grid_with_placement.end())
{
grid_with_placement[pos_of_node] = i;
i++;
}
else
{
continue;
}
}
return 0;
}
我一直在为一项任务编写这个函数,我打算实现的任务是,如果该条目还没有出现在地图中,我想添加到我的任务中。但是,我遇到了 2 个错误,并且终端显示了一堆我觉得难以理解的文本。
我的问题是2折。首先,1.我该如何纠正这个问题。2. 如果命令行显示大量错误,我应该从哪里开始纠正我的问题。
错误信息如下:
/Library/Developer/CommandLineTools/usr/include/c++/v1/__functional_base:55:21: error: invalid operands to binary expression ('const pos_in_grid' and 'const pos_in_grid')
{return __x < __y;}
解决方案
推荐阅读
- php - Yii2 与 SBADMIN - Bootstrap 4,在侧边栏中生成菜单
- angularjs - Fetch Keep Alive 未按预期工作
- android - 无法让反应原生项目在 android 上运行
- java - Spring Boot 应用程序未注册 @Repository
- visual-studio-code - 在 VS Code 中连接到远程容器的更好方法
- assembly - 内存大小/宽度和寄存器宽度之间的混淆
- arrays - 增长数组的范围最小查询
- gcc - 架构 arm64 的未定义符号:使用 vs 代码运行 c/c++ 时
- ansible - 使用数组列表安装 yum 包作为 Ansible 中的版本号
- javascript - 如何过滤包含特定值的唯一对象的数组?