Richard Richard - 1 year ago 97
C++ Question

c++: Behavior of push_back() and back() with pointers

I have two C++ lists,

std::list<T> List1
std::list<T*> List2;
. Now, I'd like to do the following operation several times:


My question: Does the reference in List2 stay valid, after each step? I.e.: Is the first element in List2 still referring to the first in List1 etc?

Answer Source

Yes, it stays valid. std::list insertion doesn't invalidate iterators (or pointers to the content in this case).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download