Why doesn't the C++ default destructor destroy my objects?

前端 未结 13 2112
刺人心
刺人心 2020-12-14 06:59

The C++ specification says the default destructor deletes all non-static members. Nevertheless, I can\'t manage to achieve that.

I have this:

class N         


        
13条回答
  •  隐瞒了意图╮
    2020-12-14 07:22

    Your argument might seem sound but that's not how things work for pointers.

    n is actually being destructed but, what this means is that the N* destructor is being called which, it does NOT destruct whatever object n is pointing to. Think of the N*'s destructor as if it were an int's destructor. It deletes its value, the same happens for a pointer, it deletes the address it is pointing to, but it doesn't need to delete whatever object is located at the address you just deleted.

提交回复
热议问题