I have some very interesting code snippets. When I delete a object, its value become zero, but the object pointer can still be manipulated, is this wierd?
#include <iostream>
#include <vector>
using namespace std;
class B
{
public:
vector<double> vec;
};
class A
{
public:
B b;
};
int main()
{
A* a = new A();
a->b.vec.push_back(1);
a->b.vec.push_back(2);
A* a1;
delete a;
cout << "before" << endl;
a1= a;
cout << a1->b.vec[0] << endl;
cout << "after" << endl;
return 0;
}
output:
before
0
after
After I delete a, its value become zero, but it still can be referenced? I don't know why?