The placement delete is used to deallocate the memory when an exception occurs in the placement new. So I ran a test:
class A {
public:
A(){
cout << "constructor" << endl;
throw 1;
}
};
void* operator new(size_t size, int i){
cout << "in placement new" << endl;
return ::operator new(size);
}
void operator delete(void *ptr, int i){
cout << "in placement delete" << endl;
::operator delete(ptr);
}
int main(){
int o = 9;
A* a = new(o) A;
}
And the placement delete function was never called, it just simply exited. Why?
Aucun commentaire:
Enregistrer un commentaire