I've written a very simple code. In created an object dynamically, and then I delete that object and assign it to zero. After that I access a member function of that object, but my program does not crash, instead it returns value.
class MyClass
{
public:
MyClass() {}
int funct() { return 0; }
};
int main()
{
MyClass *mc = new MyClass;
delete mc;
mc = 0;
// The program should crash here as I've set mc to zero after deleting
// it. But it returns the value.
int retVal = mc->funct();
return 0;
}
As per my understanding with new, delete and assignment to zero, this code should crash, or give exception.