![](/img/trans.png)
[英]Error assignment of read-only location '__result.std::_Rb_tree_const_iterator<_Tp>::operator*<long long int>()'
[英]Segmentation fault from std::_Rb_tree_const_iterator<Type>::operator++
遍历集合时出现分段错误。 堆栈跟踪指向
std::_Rb_tree_const_iterator<Type>::operator++
std::_Rb_tree_increment()
但我没有得到更多的信息。 迭代器位于函数返回的集合上
for (FactSet::factset_iterator fact_it = (*binSet_it).getDependencyGraph().getExtentionalFactSet().begin();
fact_it != (*binSet_it).getDependencyGraph().getExtentionalFactSet().end();
++fact_it) {...}
我看不到问题。 提前致谢。
您不想像这样迭代返回值。 每次迭代都会重新评估中间终止条件,因此您的end()
每次都会使用不同的集合,这意味着迭代器将永远无法达到它。
将集合缓存在本地变量中,然后从中使用begin()
和end()
。
您是否擦除循环中的元素? 在这种情况下,您需要获取擦除函数的返回值(将迭代器赋予删除后的第一个元素),并且在该回合之后不得执行++ it(否则将跳过下一个元素,或者如果已经在末尾,则可能在operator ++中导致段错误)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.