C ++数组delete操作符语法 [英] C++ array delete operator syntax

查看:73
本文介绍了C ++数组delete操作符语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我这样做后,说

美孚*阵列=新的Foo [N];

我一直删除了这样

删除[]数组;

不过,有时候我已经看到了这种方式:

However, sometimes I've seen it this way:

删除[N]数组;

,因为它似乎编译和工作(至少在msvc2005),我想知道:
是什么做的正确方法?
为什么它编译的其他方式呢?

As it seems to compile and work (at least in msvc2005), I wonder: What is the right way to do it? Why does it compile the other way, then?

推荐答案

您可以检查这个MSDN链接:删除[N]运营商。该值被忽略。

You can check this MSDN link: delete[N] operator. The value is ignored.

修改
我想这个样本code对VC9:

EDIT I tried this sample code on VC9:

int test()
{
    std::cout<<"Test!!\n";
    return 10;
}

int main()
{
    int* p = new int[10];
    delete[test()] p;
    return 0;
};

输出是:测试!

所以前pression被评为但返回值被忽略。
我很惊讶,至少可以说,我不认为这是为什么需要一个场景。

So the expression is evaluated but the return value is ignored. I am surprised to say the least, I can't think of a scenario why this is required.

这篇关于C ++数组delete操作符语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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