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

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

        
7条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-02 15:30

    You were trying to delete a NULL pointer. So, the destructor was not getting called.

    class Widget
    {   
    public:        
        Widget()
        {            
            cout<<"Widget()"<

    Output:

    operator new
    Widget()
    ~Widget()
    operator delete

提交回复
热议问题