How does delete deal with pointer constness?
Posted
by aJ
on Stack Overflow
See other posts from Stack Overflow
or by aJ
Published on 2009-04-16T13:27:02Z
Indexed on
2010/04/07
2:23 UTC
Read the original article
Hit count: 456
c++
|delete-operator
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?
© Stack Overflow or respective owner