I have a vector<int>* arr
, which is actually a 2D array.
arr = new vector<int> [size];
Is it ok that I just do
delete arr;
Will arr[i]
be automatically be deleted, since it is a standard vector?
No, you should be using delete[]
when you used new[]
.
But this is madness. You're using nice happy friendly containers for one dimension, then undoing all the goodness by resorting to manual dynamic allocation for the outer dimension.
Instead, just use a std::vector<std::vector<int> >
, or flatten the two dimensions into a single vector.
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