14

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));

?

4

1 回答 1

9

delete ptr将对 进行重载解析operator delete,因此它可能不会调用全局::operator delete

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

于 2012-05-13T17:43:13.353 回答