示例

int main(int argc, char* argv[])
{

int *a = static_cast<int *>(malloc(sizeof(int )));
delete a;
   
int *b = new int;
free(b);

return 0;
}

解决方案
使用 free() 来取消分配用 malloc() 分配的内存,而使用“delete”取消分配用“new”分配的内存。

int main(int argc, char* argv[])
{


int *a = static_cast<int*>(malloc(sizeof(int)));
free(a);
   
int *b = new int;
delete b;

return 0;
}