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));
答案 0 :(得分:8)
delete ptr
会对operator delete
执行重载解析,因此可能无法调用全局::operator delete
但不然,是的。 delete
运算符调用相关的析构函数(如果有),然后调用operator delete
。