I was reading this question Deleting a const pointer and wanted to know more about delete
behavior. Now, as per my understanding:
delete expression
works in two steps:
- invoke destructor
- then releases the memory (often with a call to
free()
) by calling operator delete.
operator delete
accepts a void*
. As part of a test program I overloaded operator delete
and found that operator delete
doesn't accept const
pointer.
Since operator delete does not accept const pointer and delete internally calls operator delete, how does Deleting a const pointer work ?
Does delete
uses const_cast internally?