来自 C++ 常见问题解答:http://www.parashift.com/c++-faq-lite/dtors.html#faq-11.9
Remember: delete p does two things: it calls the destructor and it deallocates the memory.
如果 delete 释放内存,那么这里的析构函数有什么用?
最佳答案
If delete deallocates the memory, then what's the need of the destructor here?
析构函数的要点是执行清理对象后所需的任何逻辑,例如:
- 对被销毁对象拥有的其他对象调用 delete
- 适当释放其他资源,如数据库连接;文件句柄等
关于c++ - 由于 delete 运算符释放内存,为什么我需要一个析构函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9125271/