使用delete 删除指针类型数组时报错
我是用指针型数组,并且交换了2个数组的首地址,其实就是为了把2个数组的值互相交换,然后用delete申请的内存空间时,回内存崩溃……
以下是代码
double *Vji_1=new double [m];
double *Vji=new double [m];
double *temp=new double [m];
中间的代码都是用来计算Vji_1 和 Vji 元素的值
//swap the array.
temp=Vji_1;
Vji_1=Vji;
Vji=temp;
double V00;
V00=Vji_1[0];
delete [] Vji_1;
delete [] temp;
cout<<endl;
cout<<V00<<endl;
return V00;
然后调试会报错
我跟踪了一下 每次都是在这里报错
delete [] Vji_1;
错误是这样的
Windows has triggered a breakpoint in exercise 1.exe.
This may be due to a corruption of the heap, which indicates a bug in exercise 1.exe or any of the DLLs it has loaded.
This may also be due to the user pressing F12 while exercise 1.exe has focus.
The output window may have more diagnostic information.
点击 break 报错如下:
Call stack location:
ntdll.dll!76ff542c()