Jump to content
  • Advertisement
Sign in to follow this  
schupf

Pointer to a map element

This topic is 2691 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello,

I have a map std::map<int, Foo> myMap and store a pointer to one element:
Foo* p = &myMap[22];
If I now insert into myMap, is it save to say that p still points to the same element? Or could p be invalidated after insertions into the map have taken place?

Share this post


Link to post
Share on other sites
Advertisement
Yes. This is an important feature of node-based containers (list, map, multimap).

You should find a good reference where you can look these things up. It's not too hard, seeing that the Wikipedia page on map gives you your answer in the second paragraph (although it talks about "references", this applies to pointers too).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!