+ 3
Please explain the output of the following code
How can we call the destructor, and if we could then why does the object is still usable?? https://code.sololearn.com/c32IWYnwWDvw/?ref=app
2 Réponses
+ 8
The behaviour of the following operations is undefined. There are two things undefined here:
0) Accessing a member object after calling the destructor.
1) Automatic calling of the destructor again upon encounter of } by the compiler.
Anything can happen, ranging from a sucessful run to a segmentation fault.
Read more about things here:
https://isocpp.org/wiki/faq/dtors#dont-call-dtor-on-local
http://en.cppreference.com/w/cpp/language/ub
+ 3
Because calling destructor manually just executes what's inside it, it won't destroy any object. Destructor will only destroy any object when it is called by compiler.