如何从c ++中的对象向量中删除一个项目?

-1 c++ vector erase

我有以下C++类,

class rec
{
public:
    int width;
    int height;
};
Run Code Online (Sandbox Code Playgroud)

在我的主要功能中,我有一个带rec对象的向量,

rec r1,r2,r3;
r1.height = r1.width = 1;
r2.height = r2.width = 2;
r3.height = r3.width = 3;

vector<rec> rvec = { r1,r2,r3 };
Run Code Online (Sandbox Code Playgroud)

现在我想rvec用以下方法调用擦除一个项目,

rvec.erase(remove(rvec.begin(), rvec.end(), r_remove), rvec.end());
Run Code Online (Sandbox Code Playgroud)

但我得到了这个错误:

C2678:二进制'==':找不到哪个运算符带有'rec'类型的左手操作数(或者没有可接受的转换)

Sta*_*ght 5

您需要为自定义数据结构重载operator == rec

class rec
{
public:
    int width;
    int height;
    bool operator==(const rec&  rhs) {
        return (width == rhs.width) && (height == rhs.height);
    }
};
Run Code Online (Sandbox Code Playgroud)

因为remove通过operator ==比较值