“删除"的数组形式是什么? [英] What is the array form of 'delete'?

查看:34
本文介绍了“删除"的数组形式是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用数组名称作为指针编译代码,并使用delete删除数组名称时,我收到了关于不使用数组形式删除数组的警告(我不记住确切的措辞).

When I compiled a code using the array name as a pointer, and I deleted the array name using delete, I got a warning about deleting an array without using the array form (I don't remember the exact wording).

基本代码是:

int data[5];
delete data;

那么,delete 的数组形式是什么?

So, what's the array form of delete?

推荐答案

delete的数组形式为:

The array form of delete is:

delete [] data;

但正如其他人指出的那样,您不应该为如下定义的数据调用 delete:

But as others have pointed out, you shouldn't be calling delete for data defined like this:

int data[5];

您应该只在使用 new 分配内存时调用它,如下所示:

You should only call it when you allocate the memory using new like this:

int *data = new int[5];

这篇关于“删除"的数组形式是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆