When I tried to delete end()
element from the map
using erase
I got no issues in compilation but on later printing the map.begin()
key/mapped_value I got segmentation fault:
//RELEVANT HEADERS
//main function starts
map<int, string> m;
m[0] = "hello";
m[1] = "Mello";
m.erase(m.end());
cout<<(m.begin())->second;
OUTPUT: Segmentation fault
My question is: on trying to delete the end()
element nothing would've happened to the structure of map m
as end
refers to one past the real end element, so what really triggered that segmentation fault
as the memory structure still holds same as before deletion.