繁体   English   中英

自定义类向量的迭代器查找方法

[英]iterator find method for custom class vector

我想使用迭代器的find方法来检查是否已经在向量中定义了我定义的类的实例。 我已经为该类重载了==运算符。 但是,我无法编译它。

我在这里想念什么?

谢谢你提前。

这是代码片段:

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;
}

如果操作员定义为member,则应该接受对ContourEdgeIndexes常量引用。 另外,运算符本身应该是const。

bool operator == (const ContourEdgeIndexes& rhs) const {
    return ((this->first == rhs.first) && (this->second == rhs.second));
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM