I am learning the C++ oop, why when I create an object and delete it but it still can be called even though it's destroyed. Check this simple code here. Thank you.
Code:
#include <iostream>
using namespace std;
class h
{
public:
h(){ cout << "h called\n";};
void write() { cout << "write\n";}
~h(){cout << "h destroyed\n"; };
};
int main()
{
h* pH = new h();
pH->write();
delete pH;
pH = NULL;
pH->write();
return 0;
}
Comment