c++ - Problems with list iterator and - operator -


can tell me why list iterator hates .end()-1 ? want iterato 1 before list end, under impression !

code on request

std::list<hammer::shared_ptr<hammer::actor>> collisionactorslist;  std::list<hammer::shared_ptr<hammer::actor>>::iterator _actorupdateiter =           collisionactorslist.begin(); while(_actorupdateiter != (collisionactorslist.end()-1)) // error here {     // check against every other actor      std::list<hammer::shared_ptr<hammer::actor>>::iterator _otheractorsupdateiter =  _actorupdateiter+1; // error here     while(_otheractorsupdateiter != collisionactorslist.end())     {// stuff } } 

std::list uses bidirectional iterator, doesn't support operator- or operator+. use std::prev(collisionactorslist.end()) , std::next(_actorupdateiter).

as pointed out below in comments, should aware of whether list empty. if is, these fail want. there's simple function that: collisionactorslist.empty().


Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -