从自定义数据类型向量数组C 删除



尝试从我的客户向量数组中删除非常困难。

它被定义为:

vector<Customer> VecCustomerCollection;

客户是一个对象(存储每个客户的信息)

目前试图删除这样的删除:

VecCustomerCollection.erase(emove(VecCustomerCollection.begin(), VecCustomerCollection.end(), cus), VecCustomerCollection.end());

但这给出了很多错误(我读到我需要超载,但不确定如何)

我还尝试了使用迭代器并通过向量进行迭代的方法(因为每个值都是唯一的)。

但是也无法正常工作,并整个下午都尝试使其工作。

关于如何使其工作的任何见解?谢谢!

您必须为Customer类定义operator ==或定义某些谓词,这将是该操作员的替代。在最后的情况下,您必须使用算法std::remove_if而不是std::remove

不久,您应该决定如何将类型客户的对象相互比较。编译器无法决定如何比较对象。

考虑到有错字

VecCustomerCollection.erase(emove(VecCustomerCollection...
                            ^^

最新更新