首页 > 解决方案 > 二进制表达式的无效操作数('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;}

标签: c++

解决方案


推荐阅读