vector destruction and malloc
I'm learning how to code with vectors. I wrote a few lines to try out the vector destructor. I thought it was simple enough, but the code generates a runtime error that refers to memory allocation. It seems to be saying that memory allocated to the vector had already been freed before I called the destructor.
Can you tell me what I'm doing wrong? I compiled it using gcc 4.0.1 on a MacPro running OS 10.5.3. Below is the code and the output.
Thanks!
Mike
Code:
#include <vector>
using namespace std;
int main()
{
vector<int> data;
data.push_back(1);
data.~vector<int>();
return 0;
}
OUTPUT
a.out(11915) malloc: *** error for object 0x100150: double free
*** set a breakpoint in malloc_error_break to debug