Home > Back-end >  Deleting a dynamic array of vectors
Deleting a dynamic array of vectors

Time:10-01

I believe this should be pretty simple and straightforward. Why am I getting an error? Here is the code:

std::vector<double> *myVectorArr;
myVectorArr = new std::vector<double>[10];
delete myVectorArr;

The error I get is:

munmap_chunk(): invalid pointer
Aborted (core dumped)

Why would I be getting this error?

Thanks in advance!

CodePudding user response:

You need to use the operator delete [] instead of the operator delete

delete [] myVectorArr;
  • Related