operator new()和new [] [英] operator new() and new[]

查看:70
本文介绍了operator new()和new []的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何区别


------ 1 ------

Foo * p = operator new(n * sizeof(Foo));

//东西

删除p;

-------------- -





------ 2 ------

Foo * p = new [n];

//东西

删除[] p;

------------ ---



Alex Vinokur

电子邮件:alex DOT vinokur AT gmail DOT com
http://mathforum.org/library/view/10978.html
http://sourceforge.net/users/alexvn

Is the any difference between

------ 1 ------
Foo* p = operator new (n * sizeof (Foo));
// Stuff
delete p;
---------------

and

------ 2 ------
Foo* p = new [n];
// Stuff
delete[] p;
---------------
?
Alex Vinokur
email: alex DOT vinokur AT gmail DOT com
http://mathforum.org/library/view/10978.html
http://sourceforge.net/users/alexvn

推荐答案

嗨Alex,据我所知,变量名称和

之间没有括号的区别与声明变量分别是

使用数组接受单个值和多个值。

这个a新的和删除声明也是如此。


纠正我,如果我错了

Hi Alex, to my knowledge the difference between variable names with and
without brackets has to do with declaring variables which respectively
accept a single value and multiple values usings arrays .
This also is the case with the new and delete statements.

Correct me if i''m wrong


Alex Vinokur写道:
Alex Vinokur wrote:
是否有任何区别

------ 1 ------
Foo * p = operator new(n * sizeof(Foo));
//东西
删除p;
---------------



------ 2 ------
Foo * p = new [n];
//东西
删除[] p;
---------------
Is the any difference between

------ 1 ------
Foo* p = operator new (n * sizeof (Foo));
// Stuff
delete p;
---------------

and

------ 2 ------
Foo* p = new [n];
// Stuff
delete[] p;
---------------
?




是的,绝对的。前者不应该编译。


V

-

请在邮寄回复时从我的地址中删除资金



Yes, abslutely. The former shouldn''t compile.

V
--
Please remove capital As from my address when replying by mail


Leander de Graaf写道:
Leander de Graaf wrote:
嗨Alex,据我所知,变量名与
和无括号之间的区别必须要做声明使用数组分别接受单个值和多个值的变量。
新的和删除语句也是如此。

如果我是正确的我错误
Hi Alex, to my knowledge the difference between variable names with
and without brackets has to do with declaring variables which
respectively accept a single value and multiple values usings arrays .
This also is the case with the new and delete statements.

Correct me if i''m wrong




你错了。你误读了OP的代码。请再次阅读第一部分




V

-

请删除资金As通过邮件回复我的地址



You''re wrong. You misread the OP''s code. Please read the first part
again.

V
--
Please remove capital As from my address when replying by mail


这篇关于operator new()和new []的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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