新的A [10]会带来什么回报? [英] what does a new A[10] return?

查看:74
本文介绍了新的A [10]会带来什么回报?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


上面的语句是否返回一个指向As数组的指针,或者指向初始A对象的

指针?自声明


新A


返回指向A的指针,然后新的A [10]应该返回指向A
数组,即它的类型是类似


A [] *


然而,似乎它返回A指针,即A *。标准

是否说new A [...]总是返回指向第一个A对象的指针?


谢谢,

Jess

Hello,

Does the statement above return a pointer to an array of As, or, a
pointer to the initial A object? Since the statement

new A

returns a pointer to A, then new A[10] should return a pointer to an A
array, i.e. its type is something like

A []*

However, it seems it returns an A pointer, i.e. A*. Does the standard
say "new A[...]" always returns a pointer to the first A object?

Thanks,
Jess

推荐答案

Jess写道:
Jess wrote:

你好,


上面的语句是否返回指向As的数组,或者是一个指向初始A对象的
指针?由于声明
Hello,

Does the statement above return a pointer to an array of As, or, a
pointer to the initial A object? Since the statement



后者。

The latter.


new A


返回指向A的指针,
new A

returns a pointer to A,



是。

Yes.


然后新的A [10]应该返回指向A

数组的指针,即它的类型类似于


A [] *
then new A[10] should return a pointer to an A
array, i.e. its type is something like

A []*



No.

No.


但是,似乎它返回一个A指针,即A *。
However, it seems it returns an A pointer, i.e. A*.



是。

Yes.


标准

是否说新A [...]"总是返回指向第一个A对象的指针?
Does the standard
say "new A[...]" always returns a pointer to the first A object?



我相信如此。


HTH,

- J.

I believe so.

HTH,
- J.


6月10日下午2:01,Jess< w ... @ hotmail.comwrote:
On Jun 10, 2:01 pm, Jess <w...@hotmail.comwrote:

声明上面返回一个指向As数组的指针,或者,指向初始A对象的指针是什么?由于语句
Does the statement above return a pointer to an array of As, or, a
pointer to the initial A object? Since the statement


new A
new A


返回指向A的指针,然后新的A [10]应该返回一个指向A

数组的指针,即它的类型类似于
returns a pointer to A, then new A[10] should return a pointer to an A
array, i.e. its type is something like


A [] *
A []*



你的意思是A(*)[]。它应该,但它不是。这是继承自C的C ++中一个主要的
缺陷。在实践中,它并不是b
;在超过15年的C ++中,我从来没有找到过你可能想要做一个新的A [N]或者使用
$ b中的数组新的

的情况。 $ b general。

You mean A(*)[]. It should, but it doesn''t. This is a major
defect in C++, inherited from C. In practice, it doesn''t
matter; in well over 15 years of C++, I''ve never, ever found a
case where you might want to do a new A[N], or use array new in
general.


但是,似乎它返回一个A指针,即A *。

标准是否说new A [...]总是返回一个指向

的第一个A对象?
However, it seems it returns an A pointer, i.e. A*. Does the
standard say "new A[...]" always returns a pointer to the
first A object?



是的。拖拽的类别,但正如我所说,因为新A [...]无论如何,无论是
无用,都没用。


-

James Kanze(Gabi Software)电子邮件:< a href =mailto:ja ********* @ gmail.com> ja ********* @ gmail.com

Conseils en信息东方物品/

Beratung in objektorientierter Datenverarbeitung

9placeSémard,78210 St.-Cyr-l''coco,France,+ 33(0)1 30 23 00 34

Yes. Sort of a drag, but as I say, since "new A[...]" is
useless anyway, it doesn''t matter.

--
James Kanze (Gabi Software) email: ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l''école, France, +33 (0)1 30 23 00 34


On Sun,2007年6月10日21:18:47 +0000,James Kanze写道:
On Sun, 10 Jun 2007 21:18:47 +0000, James Kanze wrote:

6月10日下午2:01,Jess< w ... @ hotmail.comwrote:
On Jun 10, 2:01 pm, Jess <w...@hotmail.comwrote:

>上面的语句是否返回指针到一个As数组,或者,一个指向初始A对象的指针?由于语句
>Does the statement above return a pointer to an array of As, or, a
pointer to the initial A object? Since the statement


> new A
>new A


>返回指向A的指针,然后新的A [10]应返回指向A />数组的指针,即其类型类似于
>returns a pointer to A, then new A[10] should return a pointer to an A
array, i.e. its type is something like


> A [] *
>A []*



你的意思是A(*)[]。它应该,但它不是。这是继承自C的继承C ++的一个主要缺陷。在实践中,它并不重要;在C ++以上的15年以上,我从未发现过你可能想要做一个新的A [N]或者使用数组的情况新的一般。


You mean A(*)[]. It should, but it doesn''t. This is a major defect in
C++, inherited from C. In practice, it doesn''t matter; in well over 15
years of C++, I''ve never, ever found a case where you might want to do a
new A[N], or use array new in general.


>然而,似乎它返回一个A指针,即A *。标准是否说新A [...]。总是返回指向第一个A对象的指针?
>However, it seems it returns an A pointer, i.e. A*. Does the standard
say "new A[...]" always returns a pointer to the first A object?



是的。拖拽的类别,但正如我所说,因为新A [...]没用了

无论如何,没关系。


Yes. Sort of a drag, but as I say, since "new A[...]" is useless
anyway, it doesn''t matter.



我可以看到在某些

情况下将其用于标量/ POD类型的一个原因:为了避免std的初始化成本: :vector has。


-

Markus Schoder

I can see one reason to use it for scalar/POD types in certain
situations: To avoid the cost of initialization that std::vector has.

--
Markus Schoder


这篇关于新的A [10]会带来什么回报?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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