新的A v.s.新A() [英] new A v.s. new A()

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

问题描述

你好,

之间有什么区别:

A * p =新A;



A * p =新A();




我知道这里一定要讨论,但只是

不容易搜索。顺便说一句,我认为

A a;

类似于建筑商电话有关的新A?

(默认的construtor电话?)对吗? br />



A a();

只是一个功能声明?

谢谢你,最好的问候,

文杰

Hello,
Is there any difference between:
A* p = new A;
and
A* p = new A();
?

I know it must have been dicussed here, but just
not easy to search. BTW, I think
A a;
is alike new A as far as constructor call concerned
(default construtor call?) Right?

And
A a();
is just a function declaration?
Thanks and best regards,
Wenjie

推荐答案

" Wenjie" <去**** @ yahoo.com>写道...
"Wenjie" <go****@yahoo.com> wrote...
之间有什么区别:
A * p = new A;

A * p = new A();



课程没有区别,POD有差异

:前者保留未初始化的对象,

后者将其初始化为零。

我知道它一定是在这里被讨论过,但只是不容易搜索。顺便说一句,我认为
A a;
就像建设者电话有关的新A一样
(默认的construtor电话?)对吗?


这是一个声明(在某些情况下的定义)

对象'a'的A类型。如果它是'a'定义,对象

是默认初始化的,对于一个类来说意味着它的c-tor

被调用,是的。


A a();
只是一个函数声明?
Is there any difference between:
A* p = new A;
and
A* p = new A();
?
There is no difference for classes, there is a difference
for POD: the former leaves the object uninitialised, the
latter zero-initialises it.
I know it must have been dicussed here, but just
not easy to search. BTW, I think
A a;
is alike new A as far as constructor call concerned
(default construtor call?) Right?
It''s a declaration (and a definition in certain circumstances)
of an object ''a'' of type A. If it''s a definition, the object
is default-initialised, which for a class means that its c-tor
is invoked, yes.

And
A a();
is just a function declaration?




是的,它是。

Victor



Yes, it is.
Victor





Wenjie写道:


Wenjie wrote:

您好,

之间有什么区别:
A * p =新A;

A * p =新A();



是的,在某些情况下有所不同。

它与POD'有关(POD =普通的旧数据结构,
基本上是一个只用内置类型构建的类或结构

并且没有成员函数,简而言之:一个结构,因为它是

ment in C)


new A

创建一个新的A类POD对象并让所有成员保持未初始化


new A()

创建一个新的POD对象,类型为A,但是0初始化所有成员。

A a();
只是一个函数声明?

Hello,

Is there any difference between:
A* p = new A;
and
A* p = new A();
?
Yes, there is a difference in certain circumstances.
It has to do with POD''s (POD = plain old data structure,
basically a class or a struct built from only builtin types
and having no member functions, in short: a struct as it was
ment to be in C)

new A
creates a new POD-object of type A and leaves all members uninitialized

new A()
creates a new POD-object of type A but 0-initializes all members.
A a();
is just a function declaration?




是的。这是一个陷阱。


-

Karl Heinz Buchegger
kb ****** @ gascad.at




" Victor Bazarov" <五******** @ attAbi.com>在留言新闻中写道:vf ************ @ corp.supernews.com ...

"Victor Bazarov" <v.********@attAbi.com> wrote in message news:vf************@corp.supernews.com...
班级没有区别,


非POD课程(但你知道的。)

POD有差异:前者让对象未初始化,
后者将其初始化为零。
There is no difference for classes,
non-POD classes (but you knew that).
there is a difference
for POD: the former leaves the object uninitialised, the
latter zero-initialises it.



这篇关于新的A v.s.新A()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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