编译代码时safe_iterator.h 中发生错误
Error happening in safe_iterator.h when I compile my code
好吧,伙计们。我知道我已经发布了这段代码(我现在已经从以前修复了它),但似乎仍然有一些事情发生,我不想编辑我以前的帖子以包含另一个问题(因为这违反了规则)。
当我编译下面的代码时,我收到来自库深处的错误消息
safe_iterator.h: **error: no match for 'operator<' in '(+ __lhs)->__gnu_debug::_Safe_iterator<_Iterator, _Sequence>::base [with _Iterator = std::_Rb_tree_iterator<std::pair<const int, int> >, _Sequence = __gnu_debug_def::map<int, int, std::less<int>, std::allocator<std::pair<const int, int> > >]() < (+ __rhs)->__gnu_debug::_Safe_iterator<_Iterator, _Sequence>::base [with _Iterator = std::_Rb_tree_iterator<std::pair<const int, int> >, _Sequence = __gnu_debug_def::map<int, int, std::less<int>, std::allocator<std::pair<const int, int> > >]()'**
有什么想法吗?请不要对我太苛刻。我有点n00b。:)
// Returns the mode (most common element) of an integer array
int mode(int* arrPtr, int size) {
assert (size > 0);
std::map<int,int> M;
for (int k = 0; k < size; ++k)
M[arrPtr[k]]++;
std::pair<int,int> maxpair(M.begin()->first, M.begin()->second);
for (std::map<int,int>::iterator it = M.begin() + 1; it < M.end(); ++it)
if (it->second > maxpair.second) maxpair = *it;
return (maxpair.first);
}
迭代器不实现operator<
你应该使用it != end
,当心size
为零!
相关文章:
- 警告处理为错误这里有什么问题
- "error: no matching function for call to"构造函数错误
- boost::进程间消息队列引发错误
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- QT在错误的班级中寻找空位
- 造成致命错误:boost/fusion/iterator/equal_to.hpp 没有这样的文件或目录
- 错误:与'operator='不匹配(操作数类型为"std::map<int、double>::iterator
- 自动,错误:MAP ITERATOR没有名为“ First”的成员
- "Deque iterator not dereferencable"错误
- 使用 top() 时收到错误"cannot dereference out of range deque iterator"
- C++ 布尔向量错误:赋值时"iterator not dereferencable"
- 错误: C2039: 'pointer': 不是 'QJsonObject::iterator' 的成员
- MSVC 中"vector<bool> iterator not dereferencable"错误,但在使用 g++ 编译时可以完美运行
- 错误:无法将'std::basic_string<char>::iterator ...'转换为参数"1"的"常量字符*..."
- Iterator::Begin()函数错误
- 为什么擦除End-Iterator不会给shared_ptr分段错误
- std::矢量在 MFC CArray 中 - 在将元素添加到 CArray 后出现"iterator not dereferencable"错误
- 标识符'iterator'的语法错误
- map<int、int>::iterator 的编译错误,运算符 = 不匹配