0

I have a map of objects and I copied one object to the local variable and then delete the object in the map. Could this create a problem when I work on local object?

std::map<int, obj>::iterator it2 = mymap.find(objnum);
mylocalobj = it2->second;
mymap.erase(it2);
//continue working on mylocalobj 
4

1 回答 1

1

Copy is the key word here, if you've copied the object in the map, then what happens to the original no longer matters, unless you haven't implemented copying semantics correctly in your obj class.

If you haven't done this then you should regard your code as bugged.

于 2013-09-25T12:24:15.177 回答