为何不能delete?
代码如下:
Opdata-> FileName= "file1 ";
if(Opdata-> Execute())
{
String str3;
int i;
str3 = Opdata-> FileName;
char *temp3 = new char[sizeof(str3)+1];
strcpy(temp3,str3.c_str());
i = read_ref_opt_data(temp3);
delete temp3; //????????????????????????
if(i==-1)
MessageDlg( "读取数据文件出错。 ",mtWarning,TMsgDlgButtons() < <mbYes,0);
}
temp3用new定义,使用后用delete删除,但是调试时总是在delete temp3; //????????????????????????行出错?为什么不能delete?请指教。谢谢!
[解决办法]
delete [] temp3;
[解决办法]
char *temp3 = new char[str3.Length()+1];
......
delete []temp3;
[解决办法]
if (temp3 != NULL)
{
delete[] temp3;
temp3 = NULL;
}