我有一个类,构造函数如下:C++如何从类类型的向量中删除重复项?
myclass(int=0,string="",int=0,string="",int=0,int=0,
int=0,int=0,string="",int=0,int=0);
与
vector<myclass>myvect;
矢量进行排序,我试图删除重复 ,这是这种类型的元素的矢量不工作:
std::vector<myclass>::iterator it;
it=std::unique (myvect.begin(), myvect.end());
myvect.resize(std::distance(myvect.begin(),it));
我得到这个错误
:algorithm(1862): error C2678: binary '==' :
no operator found which takes a left-hand operand
of type 'myclass' (or there is no acceptable conversion)
任何想法,为什么? 有什么办法可以从这个向量中删除重复?
为'myclass'实现'operator =='? – Morwenn 2013-05-06 17:39:05
一个简单的解决方案是实现您自己的相等运算符。 – 2013-05-06 17:39:08