Jump to content
  • Advertisement
Sign in to follow this  
schupf

Pointer to a map element

This topic is 2778 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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!