Technically correct C ++ (from now on using editing with delete[] )
The code will compile and run without errors.
However, when creating C ++ code, you very rarely use the new [] and delete [], and you are much more likely to use a vector or use a string.
If you really want to allocate an array with a new [], you might want to use boost :: shared_array to control its deletion. Otherwise, you could use shared_ptr, but you would have to add your own debiter that calls delete [].
This method is called RAII (Resource Initialization is Initialization), which ensures that for any resource that you allocate, you already take care of its subsequent disposal, no matter what happens afterwards (including any exceptions that may be thrown).
source share