调用operator new noexcept 的问题
程序代码:
#include <iostream> #include <new> #include <cstdio> using namespace std; struct A { void *operator new(size_t size) { cout<<"operator new"<<endl; malloc(size); } void operator delete(void *p) { cout<<"operator delete"<<endl; free(p); } void *operator new(size_t size,const nothrow_t &thorw_value) noexcept { cout<<"operator new noexcept"<<endl; malloc(size); } void operator delete(void *p,const nothrow_t &nowthrow_value) throw() { cout<<"operator delete noexpect."<<endl; free(p); } }; int main() { A *a1=new A; delete a1; A *a2=new(nothrow) A; delete a2;//为什么调用的是 operator delete 而不是 operator delete noexpect return 0; }