Why is not deleting an object that has a destructor with a side effect undefined behavior in C++11?

前端 未结 4 715
心在旅途
心在旅途 2020-12-11 04:03

This answer quotes C++11 Standard 3.8:

if there is no explicit call to the destructor or if a delete-expression (5.3.5) is not used to release the sto

4条回答
  •  -上瘾入骨i
    2020-12-11 04:17

    I believe this is put into the standard to allow for garbage collection. And to point out that C++ behaves differently that some other languages, by not calling destructors while collecting.

    It specifically says that storage can be reused without calling the destructors of the objects in that memory area. If the program depends on the destructors being run, it will not work as expected.

    If it doesn't depend on the destructors, all is fine.

提交回复
热议问题