I have two C++ lists, std::list<T> List1
and std::list<T*> List2;
. Now, I'd like to do the following operation several times:
List1.push_back(new_object);
List2.push_back(&List1.back());
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?
Yes, it stays valid. std::list
insertion doesn't invalidate iterators (or pointers to the content in this case).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With