Using delete on new[] is undefined, but that doesn't mean it won't work. It may or may not work, so it's not really a good demonstration of destructors firing or not. You may get different results depending on compiler and platform.
Printable View
Using delete on new[] is undefined, but that doesn't mean it won't work. It may or may not work, so it's not really a good demonstration of destructors firing or not. You may get different results depending on compiler and platform.
Yes, it's undefined behavior, I know. My point was not to show what will happen with destructors, but what might happen.
On my system for example delete on new[]ed array will fire just one destructor, and free won't fire any.
Well... again, the behavior might change. It might look fine on the OP's system. I get the point. Perhaps it would have been better if you showed some output of what could happen?