error C2678: 二进制“==”: 未找到采用左手操作数类型的运算符

error C2678: binary '==': no operator found which takes a left-hand operand of type

我正在尝试制作一个解决基于图像的迷宫的程序。在对我连接迷宫中的顶点以创建边的部分进行编程时(我想将迷宫制作成图形)我遇到了这个错误。这似乎是因为 std::find 但我不知道出了什么问题。我已经尝试搜索问题,但似乎找不到我想要的内容。

这是我的代码中有问题的部分:

// the struct used to define the coordinates
struct pixelCoord {
int x, y;

pixelCoord(int paramx, int paramy) : x(paramx), y(paramy) {}};

{...}

std::vector<pixelCoord> vertices;

// adding vertices as pixel coordinates on my image
{...}

// initializing graph
Graph g(vertices.size());

// searching for and adding edges to graph
for (size_t k = 0; k < vertices.size(); k++) {
    int l = 1;
    while (maze_bmp.getPixel(vertices[k].x, (vertices[k].y + l))[0] == 255) {
        ptrdiff_t next_vertex_pos = std::find(vertices.begin(), vertices.end(), pixelCoord(vertices[k].x, (vertices[k].y + l))) - vertices.begin();
        //if (next_vertex_pos >= vertices.size()) {
        //  g.addEdge(k, next_vertex_pos, l);
        //  break;
        //}
        l++;
    }

此外,maze_bmb.getPixel(...) 只是一个函数,用于 return 像素的 RGB 值进行比较,仅此而已。

谢谢!

为了对您已实现的 class/struct 使用“==”运算符,您需要为 class 重载“==”运算符。您可以查看此 link 以了解有关重载运算符的更多信息:Operator Overloading