Reputation: 501
What is the difference between delete x;
and ::operator delete(x);
? I understand they are different, but I can't figure out quite what the difference is. My specific use case is that I have an object that must be allocated with ::operator new(size_t)
and later initialized with the placement new operator. However, I would really like to be able to deallocate it with delete x;
rather than ::operator delete(x);
, so I would like to know when these two methods (no pun intended) might do different things, so I can tell when (if ever) it is safe to use them interchangably.
Upvotes: 1
Views: 321
Reputation: 8598
delete x
is a delete expression
.
::operator delete(x)
is a deallocation function
.
The delete expression will call the destructor (if it exists) and then the deallocation function. Calling the deallocation function directly will bypass the destructor.
Upvotes: 5
Reputation: 13134
The only difference is that ::operator delete()
will not call destructors where delete
would.
Upvotes: 2