Y
Yin99
Why am I still able to use this object even though I have deleted it?
The Output I get is:
Cat Constructs
Cat De-structs //deleteing object
Cat Eats. //My question- why does object still work?
Thanks
yin99
----- BEGIN CODE SAMPLE ---------------
#include <iostream>
using namespace std;
class Cat
{
public:
void sleep() { cout << "\n Cat sleeps! \n "; }
speak() { cout << "\n MEOW! \n "; }
Cat() { cout << "\n Cat Constructs \n" ; }
~Cat() { cout << "\n Cat De-structs \n" ; }
void eat() { cout << "\n Cat Eats.\n" ;}
private:
};
int main ()
{
Cat *pearl = new Cat();
delete pearl;
pearl->eat(); //Works!
return 0;
}
The Output I get is:
Cat Constructs
Cat De-structs //deleteing object
Cat Eats. //My question- why does object still work?
Thanks
yin99
----- BEGIN CODE SAMPLE ---------------
#include <iostream>
using namespace std;
class Cat
{
public:
void sleep() { cout << "\n Cat sleeps! \n "; }
speak() { cout << "\n MEOW! \n "; }
Cat() { cout << "\n Cat Constructs \n" ; }
~Cat() { cout << "\n Cat De-structs \n" ; }
void eat() { cout << "\n Cat Eats.\n" ;}
private:
};
int main ()
{
Cat *pearl = new Cat();
delete pearl;
pearl->eat(); //Works!
return 0;
}