Hi!
I am not too expert in C++ programming.
I created a class (Pig), then I created an object (Jack the Pig).
In the function Kill, I call the destructor, but it doesnt't "kill" (destroy) my Jack the Pig, because in the next line, I can feed him.
So my question is that why can't I destroy my object (Jack The Pig)?
Thanks for your help
#include "StdAfx.h"
#include <iostream>
class Pig
{
public:
Pig();
~Pig();
void Feed(int f);
void Kill();
private:
int Weight;
};
Pig::Pig()
{
Weight=20;
}
Pig::~Pig()
{
std::cout << "Pig is killed!\n\n";
}
void Pig::Feed(int f)
{
Weight+=f;
std::cout << "The pig's weight is: " << Weight << "kg.\n";
}
void Pig::Kill()
{
Pig::~Pig();
}
int main()
{
Pig Jack;
Jack.Feed(20);
Jack.Kill();
Jack.Feed(20);
return 0;
}