迭代器查找自定义类vector的方法
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;
}
操作符应该接受对ContourEdgeIndexes
的常量引用,如果它被定义为成员。操作符本身也应该是const。
bool operator == (const ContourEdgeIndexes& rhs) const {
return ((this->first == rhs.first) && (this->second == rhs.second));
}
相关文章:
- 使 std::vector 分配对齐内存的现代方法
- 我无法使用C++指针指向类方法返回的 std::vector
- 在自定义 std::vector-like 容器中处理指针和非指针模板类型的最佳方法是什么?
- 在 std::vector<无符号字符中存储任意数据的方法>
- 连接和压缩标准::vector<std::字符串的最佳方法>
- C++中的多维数据集:从 std::vector 的 2D 数据到 std::vector 的 2D 网格的最干净方法?
- 向后迭代 std::array 或 std::vector 的正确方法是什么?
- 使用 std::vector::swap 方法在C++中交换两个不同的向量是否安全?
- 有没有更快的方法可以在 std::vector 中插入元素
- 为什么 vector 的方法调整大小会创建一个额外的对象?
- 将vector<vector<double>>从x86平台中创建的一个进程发送到x64中构建的另一个进程的最快方法是什么
- 使输出流式处理运算符适用于 boost::variant<std::vector<int>、int、double 的正确方法是什么>
- 释放 std::vector 中指针内存的最有效方法是什么?
- 编译错误 std::vector<std::shared_ptr<T>>迭代器和擦除方法
- C++ std::vector 赋值方法
- 使用虚拟变量对 std::vector 内部循环进行切片的最佳方法
- 如何在不使用 vector::erase() 的情况下编写自定义 Vector 方法来删除元素?
- STL vector.insert 方法期望_InputIterator作为参数
- 动态创建 std::vector 并将其传递给另一个函数的各种方法
- 从 std::vector 创建 OpenCV 垫子的有效方法