In the following code, when I add the line indicated by the arrow, it gives an error:
Error in `./a.out ': double freedom or corruption (fasttop): 0x00000000007a7030 * Canceled (the kernel is reset)
The code works if I do not use a destructor. Any idea?
#include<iostream>
#include<vector>
struct Element
{
int *vtx;
~Element ()
{
delete [] vtx;
}
};
int main ()
{
Element *elm = new Element [2];
elm[0].vtx = new int [2];
std::vector <Element> vec;
vec.push_back (elm[0]);
vec.push_back (elm[0]);
return 0;
}
source
share