c++ - 来自 std::_Rb_tree_increment (__x=0x1) 的段错误

标签 c++ iterator set

我在迭代集合时遇到段错误。

堆栈跟踪指向:

  0x000000081193ccc5 in std::_Rb_tree_increment (__x=0x1) at /libstdc++/src/tree.cc:68
  0x0000000806c3107e in std::_Rb_tree_const_iterator<test *>::operator++     at stl_tree.h:266

但我没有得到更多信息,但崩溃的最后一行如下所示。

迭代器遍历一个集合。

 typedef std::set<test*,test_less> test_set_t;

 test_set_t& set(bt->getSet());   // getSet() will return reference to the class bt member variable set

 test_set_t::iterator pos = set.begin();

 test empty(val);
 test* last_ptr = &empty;

 for (; pos != set.end(); last_ptr = *pos++) {       // gdb shows this as last line

我看不到这个问题。提前致谢。

最佳答案

很可能该集合为空,或者您删除了 pos 在迭代时指向的项目。

关于c++ - 来自 std::_Rb_tree_increment (__x=0x1) 的段错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9034749/

相关文章:

c++ - 如何强制 gcc 忽略本地化

c++ - 二进制模式下的 std::ifstream 和 C++ 中的区域设置

java - 迭代器 vs for 循环以及为什么像 for 循环一样引入迭代器?

java - 递归获取幂集

algorithm - 如何找到从k个子集中选择一个的组合数

c++ - 函数开销会使程序减慢 50 倍吗?

c++ - 结构化异常处理程序 (SEH) 不会捕获堆损坏

C++接口(interface)设计问题

c++ - STL vector 、迭代器和插入 (C++)

c++ - 模板 C++:如何访问 std::map 和 std::set 的迭代器值?