c++ - use erased element in map -


i'm wondering if can still access/modify data of erased element in map inside function following:

struct custstruct {   int a;   int b; };  void useaftererase() {   map<int, custstruct> mymap;   mymap[0] = {0,1};   mymap[3] = {2,3};   mymap[4] = {4,5};    auto itr = mymap.find(3);   auto & element = itr->second;    mymap.erase(itr);    // access after erased   element.a = 100;   element.b = 100;    cout << element.a << " " << element.b << endl; } 

assume single thread , access/modify right after deletion before map modified access/modify safe?

it's never safe. object destroyed when it's removed map. (if not, when be?)


Comments

Popular posts from this blog

How to understand 2 main() functions after using uftrace to profile the C++ program? -

c# - Update a combobox from a presenter (MVP) -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -