+ 1
When is the destructor "called"?
Dunno if "called" is the right term but when is an object destroyed and the destructor called?
7 Réponses
+ 1
When you delete the object via pointer, when the actual object leaves scope (at the end of the block {}) or when you call the destructor explicitly.
+ 2
This answers are still somewhat unclear for me but I guess I'll find out after some practice and research
but thank you alot for commiting to help me
+ 1
When the object is removed from memory as it's no longer needed destructor is called.
+ 1
Do you mean when I use delete obj; the destructor is called?
Or for when the object is used the last time in a programm?
+ 1
As soon the object lose its scope that is life time of variable is finished.
+ 1
I found an answer on stackoverflow about this "out of scope" thing and understood it finally
Thanks for the answers, I just wasn't understanding this scope stuff but now I got it
0
If the object was created as an automatic variable, its destructor is automatically called when it goes out of scope. If the object was created with a new expression, then its destructor is called when the delete operator is applied to a pointer to the object.