Someone please explain this . So far I know, I can not access an allocated memory after deleting it. If I am wrong please correct me.
#include <iostream>
using namespace std;
class A
{
int x;
public:
A()
{
x = 3;
cout<< "Creating A" <<endl;
}
~A()
{
cout<< "Destroying A" <<endl;
}
int getX()
{
return x;
}
};
int main(int argc, const char * argv[])
{
A* a = new A();
delete a;
cout<< a->getX()<<endl;
return 0;
}
And the output shows as follows !
Creating A
Destroying A
3
I don't understand how can I call getX()
after deleting a