[英]iterator find method for custom class vector
I want to use find method of iterator to check if an instance of class I have defined already in the vector or not. 我想使用迭代器的find方法来检查是否已经在向量中定义了我定义的类的实例。 I have overloaded the == operator for the class.
我已经为该类重载了==运算符。 However, I couldn't get it to compile.
但是,我无法编译它。
What am I missing here? 我在这里想念什么?
Thanks n advance. 谢谢你提前。
here is a snippet from the code: 这是代码片段:
vector<ContourEdgeIndexes>::iterator it = find(contourEdges.begin(),contourEdges.end(),contourEdgeCand);
if(it != contourEdges.end()) {
contourEdges.erase(it);
}
compiler gives this error:
error: no matching function for call to ‘find(std::vector<ContourEdgeIndexes>::iterator, std::vector<ContourEdgeIndexes>::iterator, ContourEdgeIndexes&)’
edit:
and here is the overloaded == operator:
bool operator == (ContourEdgeIndexes& rhs) {
if((this->first == rhs.first) && (this->second == rhs.second))
return true;
else
return false;
}
Your operator should accept constant reference to ContourEdgeIndexes
, if it defined as member. 如果操作员定义为member,则应该接受对
ContourEdgeIndexes
常量引用。 Also operator itself should be const. 另外,运算符本身应该是const。
bool operator == (const ContourEdgeIndexes& rhs) const {
return ((this->first == rhs.first) && (this->second == rhs.second));
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.