I have deque and want to iter it backwards. I also need the index (otherwise I’d use the reverse_iterator) so I tried:
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 ) );
but I get a sigsev. After debugging I get that index was -65. I checked the _children.size( ) by
unsigned si = _children.size( );
and it is 4294967232. And
long s = _children.size( ) - 1;
is -65. How do I get such values? And how to fix this?
You should use the
reverse_iterator. If you want to keep track of an index, you can add a variable to your for loop like this:This is les error-prone than what you are doing.