Question : References in dynamic objects

Is it safe to return a reference to values on objects that are dynamic?

For instance a std::map obviously can grow and shrink to your heart's content. So let's say you get a reference to a particular value inside a map object, then your program goes along and adds several values to the map, deletes several values (but not the value you have a reference for), changes values, etc. After all that, when you try to access your reference will it still be accessible even though the map has had to dynamically allocate/deallocate memory in-between?

Let me know if that's not quite clear.


Answer : References in dynamic objects

The answer depends on the STL container. Node based containers such as map and set do not invalidate existing contents when adding or deleting but containers such as vector and deque do.

My article on STL containers explains this and a lot more.
Random Solutions  
programming4us programming4us