You add the element into the vector and then you store a pointer to that element in the map. The problem with this is if you keep adding items to the vector, the vector is going to need to grow which means allocating new memory. This means that the elements in the vector are no longer where they used to be which means all of the pointers in the map are now dangling(point to garbage).

The simple fix would be to store the element in both places. You could also create a std::shared_ptr and store the shared_ptr in both containers.