Hi!
I created an object (Jack the Pig) in the dynamic memory (heap).
Because it is a pointer, I can erase it by delete.
So I deleted Jack the Pig, but it is not deleted, because Jack->Row function still is working (writes out Rooooow).
Why can Jack->Row function still work, if before it I deleted Jack the Pig object?
#include "StdAfx.h"
#include <iostream>
class Pig
{
public:
Pig(){};
~Pig() {std::cout << "Pig is killed!\n";}
void Rof() {std::cout << "Roooooof!\n";}
};
int main()
{
Pig* Jack;
Jack = new Pig;
Jack->Rof();
delete Jack;
std::cout << "-----------\n";
Jack->Rof();
return 0;
}