Why does this code executed in debug mode trigger a breakpoint?
#include <list>
void main() {
std::list<int>::iterator* iterators = new std::list<int>::iterator[50];
delete iterators;
}
Why does this code executed in debug mode trigger a breakpoint?
#include <list>
void main() {
std::list<int>::iterator* iterators = new std::list<int>::iterator[50];
delete iterators;
}
As said in comments, if you instantiate an array using
... = new name[];
you must use
delete [] name;
When you use the operator new[] you must also use the operator delete[], otherwise it is an undefined behavior.
You can check this question for more information: Is delete[] equal to delete?