Petar Putar Visnjic Petar Putar Visnjic - 1 year ago 127
C++ Question

How to return pointer of a std::pair from map and put it to vector<*std::pair...>

As title says, how can I get specific pair pointer from my map and put it to vector?
Here is my code:

std::map<std::string, Object*> scene_objects;
std::vector<std::pair<std::string, Object*>*> scene_objects_layers;

scene_objects_layers.insert(scene_objects_layers.begin(), scene_objects.find(*object->getName())); //not working

Answer Source

You can't. If you read the map documentation you will see that nothing returns pointers to pairs. And there's not really anything that returns references to pairs with a useful lifetime, either.

So either store actual pairs in your vector (is there any real reason to use pointers to pairs?), or create copies of the pairs with new pair....

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download