Can someone explain what is happening in the following code?
#include <iostream>
#include <vector>
#include <map>
using namespace std;
int main()
{
vector<int> v;
map<char*,int*> m;
v.push_back(99);
m["TEST"]=&v[0];
cout<<"Vec size: "<<v.size()<<" : "<<v[0]<<endl;
v.erase(&v[0]);
cout<<"Map: "<<*m["TEST"]<<endl;
cout<<"Vec size: "<<v.size()<<endl;
return 0;
}
I don't understand why I am getting "99" from this line of code
cout<<"Map: "<<*m["TEST"]<<endl;
I erased the vector element and the map only contained the address to
that vector element...yet I am still getting the value I pushed_back.
What is happening behind the scenes? Is this code safe?
Any help would be appreciated