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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
No, you should be using
delete[]when you usednew[].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.