void * intptr = new int;
delete (int *) intptr;
Is the (int *)
type cast required?
Yes.
The type must match that which was new'd. The only time it doesn't have to match is deletion of a derived type through a base pointer, where the base type has a virtual destructor.
Yes. Since C++ is not an everything-is-and-object language, the delete command must know the type of what you want to delete in order to know how to delete it.
3 destructors for int will be called.
There's no such thing as a "destructor for int". delete/delete[] will only call a destructor for things that aren't POD or POD-class types.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With