delete a NULL pointer does not call overloaded delete when destructor is written

前端 未结 7 2047
慢半拍i
慢半拍i 2021-02-02 15:05
class Widget
{
    public:
        Widget() {
            cout<<\"~Widget()\"<

        
7条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-02 15:32

    Would like a leave a comment, instead of answer, didn't have enough privileges being a new member.

    An exception is being raised during the creation of object. The destructor is not getting called, as the object itself is not created.

    That you can also observe, as the messages from the constructor & destructor are not getting displayed.

    But, the delete is being called when the destructor is not defined. If thought in the directon that when destrcutor is not defined, C++ Compiler considers it as any other operator, the compiler by default provides a destructor when not defined.

提交回复
热议问题