删除vs运算符删除(和void指针)

时间:2012-05-13 17:18:46

标签: c++ destructor void-pointers delete-operator

delete ptr仅与此operator delete(ptr)不同,delete调用ptr析构函数?或者换句话说,delete ptr首先调用ptr然后operator delete(ptr)的析构函数来释放已分配的内存吗?然后delete ptr在技术上等同于以下内容:

T * ptr = new T;

//delete ptr equivalent:
ptr->~T();
::operator delete(static_cast<void *>(ptr));

1 个答案:

答案 0 :(得分:8)

delete ptr会对operator delete执行重载解析,因此可能无法调用全局::operator delete

但不然,是的。 delete运算符调用相关的析构函数(如果有),然后调用operator delete