Possible Duplicate:
C++: Delete this?
There is a class Foobar created on heap. I want to exit application when it dies. It must die, when I call die() function. There are some private properties created on heap - I also need to delete them. I wrote that code:
Foobar::Foobar()
{
m_var = new int(1);
}
Foobar::~Foobar()
{
delete m_var;
exit(0);
}
void Foobar::die()
{
delete this;
}
The question is in delete this
line. If I call it, will Foobar::~Foobar()
be called, or not?
P.S. If there is better solution, suggest it, please.