二进制“==”: 没有找到接受“Point”类型的左操作数的运算符(或没有可接受的转换)

every blog every motto: You will never know unless you try

0. 前言

问题小记

1. 正文

报错:

二进制“==: 没有找到接受“Point”类型的左操作数的运算符(或没有可接受的转换)

解决方法:
重载==

// 结构体
struct Point
{
    
    
	int x;
	int y;

	// 重载==
	bool operator==(const Point& p)
	{
    
    
		if (this->x== p.x&&this->y == p.y)
		{
    
    
			return true;
		}
		return false;
	}
};

说明: 因为程序中要对vector中的Point结构体进行比较是否相等。

参考文献

[1] https://blog.csdn.net/weixin_39190382/article/details/108059569

猜你喜欢

转载自blog.csdn.net/weixin_39190382/article/details/108102908
今日推荐