Vector iterators

后端 未结 7 1101
再見小時候
再見小時候 2021-01-29 04:45

I have a the following code.

vector* irds = myotherobj->getIRDs();//gets a pointer to the vector
for(vector::iterator it = ir         


        
7条回答
  •  星月不相逢
    2021-01-29 05:24

    You can get a pointer from an iterator by doing &*it. You get a pointer to the actual IRD object stored inside the vector. You can modify the object through the pointer and the modification will "stick": it will persist inside the vector.

    However, since your vector contains the actual objects (not pointers to objects) I don't see any point in dynamic_cast. The type of the pointer is IRD * and it points to IRD object.

    The only case when the dereferenced iterator might refer to a copy (or, more precisely, to a proxy object) is vector, which might be implemented as a bit-vector.

提交回复
热议问题