This thread encouraged me to try out a multi-map, so forgive me for some newb stuff. The multi-map is basically a binary tree which has its contents sorted via the key. Therefor, the fast searching time of your map is wasted when you search via the value.
If you can ensure that your keys are always unique, then erasing a node in the map is as simple as:
If your key values are not unique, then that code will only erase the first pair that it finds and doesn't work the way you'd want. You need to find the range of said key, and then search through that range looking for your value (if you want to follow my lead).
I've been playing with a file from a game, and thought I'd play with multi-maps with this file:
btw, the incrementing works fine on my computer.
// Techs is a class holding (string, int, string)
multimap<int, Tech> techs;
while (temp.read(input).good()) // Reads the line of the file
techs.insert(pair<int, Tech>(temp.cost, temp));
// This is to simulate your "CEntityManager* obj"
if (temp.name == "FUSION")
hold = new Tech(temp.name, temp.cost, temp.era);
// The multi-map key's are the cost of the tech
// These two lines create a range with these key values
range = techs.equal_range(8000); // "FUSION" happens to have a cost of 8000
// Find the "CEntityManager* obj"
multimap<int, Tech>::iterator iter;
for (iter = range.first; iter != range.second; iter++)
if (iter->second == *hold) break;
// Erase it
//Looks good to me
for (iter = techs.begin() ; iter != techs.end() ; iter++)
So I would imagine you could use your "name" variable to find the range, and then look through that range with your "*obj"