!!!!"delete this" in destructor !!!!

Hi,

 i don't understand why having a delete this; in the destructor cause a stack overflow?, then how to make a destructor destroying the current instance?

Thank u for advice。
Last edited on
You need delete only where there is a corresponding previous new.
the destructor is supposed to delete everything in the instance. it cant delete itself. ie if i have members int * a, *b, *c, i would delete those
> i don't understand why having a 'delete this' in the destructor cause a stack overflow?
take a look at the call stack


> then how to make a destructor destroying the current instance?
when the destructor ends, all the members of the class would be destroyed.
i don't understand why having a 'delete this' in the destructor cause a stack overflow?

What does delete this do? It calls the destructor again, which calls itself again and again, and again until you run out of stack space.

No need to delete this in the destructor.
Last edited on
It means with no pointers in class, an empty destructor does the work,
and delete calls the destructor.

Thank u very much, everyone.
Topic archived. No new replies allowed.