+ 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

1st Jan 2019, 12:27 PM
Vedansh
Vedansh - avatar
2 ответов
+ 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
1st Jan 2019, 1:23 PM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 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.
2nd Jan 2019, 4:14 PM
#DARK_PROGRAMMER_✔
#DARK_PROGRAMMER_✔ - avatar