我有双端队列并想向后迭代它。我还需要索引(否则我会使用 reverse_iterator)所以我尝试了:
if ( _children.size( ) > 0 ) // debugging purpose
{
unsigned si( _children.size( ) ); // debugging purpose
int s( _children.size( ) - 1 ); // debugging purpose
for ( unsigned c ( 0 ) ; c < _children.size( ) ; ++c )
if ( this->_children[ ( _children.size( ) - 1 ) - c ]->Topmost( ) &&
this->_children[ ( _children.size( ) - 1 ) - c ]->BorderRectangle( ).IsIn( X , Y ) )
return std::pair< int, WindowPointer >( ( _children.size( ) - 1 ) - c, this->_children[ ( _children.size( ) - 1 ) - c ]->WindowAt( x, y ) );
但我得到了一个 sigsev。调试后我得到的索引是-65。我通过
检查了 _children.size( )unsigned si = _children.size( );
它是 4294967232。
long s = _children.size( ) - 1;
是 -65。我如何获得这些值(value)?以及如何解决这个问题?
最佳答案
您应该使用reverse_iterator
。如果你想跟踪一个索引,你可以像这样在你的 for 循环中添加一个变量:
int counter = 0;
for (xx::reverse_iterator it = yy.rbegin(); it != yy.rend(); ++it, ++counter) {
// Do something
}
这比您正在做的更不容易出错。
关于c++ - 负数或超大 STL 双端队列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12987284/