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

前端 未结 3 1696
孤独总比滥情好
孤独总比滥情好 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:50

    I'm not an expert on the STL, but I believe the reason it fails to compile is because an iterator is an object that points to another object. In other words, an iterator is a generalization of a pointer. So to do what you'd want with minimal changes to your code, you would first need to de-reference the iterator to get at the value it contains. You'd then use the '&' to get its address and would then assign that address to your pointer variable. This is why ptr=&*it; works.

提交回复
热议问题