Getting value of std::list<>::iterator to pointer?

前端 未结 3 1695
孤独总比滥情好
孤独总比滥情好 2021-02-01 07:30

How can i loop thru a stl::List and store the value of one of the objects for use later in the function?

Particle *closestParticle;
for(list::ite         


        
3条回答
  •  情歌与酒
    2021-02-01 07:46

    For a list, the only way to invalidate an iterator is to erase it. So I suspect you're calling list.erase(p1) at some point in the loop. You need to make a copy of the iterator, move p1 back one, and then erase the copy.

    EDIT: Oh wait, did you mean it doesn't compile? If so, see @sbi's answer. But you really need to word your question in a good way. What is your compile error? Or does it fail at run-time? In this case, however, I believe you mean a compile error.

提交回复
热议问题