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

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

问题描述

当我使用数组名称作为指针编译代码,并且使用 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 [] data;

编辑:但是正如其他人所指出的,对于如下定义的数据,调用 delete

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

int data[5];

您只有在使用 new 像这样:

int *data = new int[5];

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

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