“new classname”和“new classname()”相同吗? [英] Is `new classname' the same as `new classname()' ?

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

问题描述



我看到一些代码使用new classname来获得一个指向

a类对象的新对象,但有些代码却使用了

`new classname()''。

这两个用法是否相同?


谢谢。

-

Hongzheng Wang

电子工程系

清华大学
wa ****** @ mails.tsinghua.edu.cn

解决方案

" Hongzheng Wang" < WA ****** @ mails.tsinghua.edu.cn>写道...

我看到一些代码使用`new classname''来指向
一个新的classname对象,但有些代码使用了
`new classname()''。
这两个用法是否相同?




对于POD,它们不是。前者没有初始化,

后者默认初始化,IIRC。


Victor


< blockquote>

" Victor Bazarov" <五******** @ comAcast.net>在消息中写道

news:akyzb.416658


Fm2.425058@attbi_s04 ...

" Hongzheng Wang" < WA ****** @ mails.tsinghua.edu.cn>写道...

我看到一些代码使用`new classname''来指向
一个新的classname对象,但有些代码使用了
`new classname()''。
这两个用法是否相同?



对于POD,它们不是。前者使其未经初始化,后者使其默认初始化,IIRC。

Victor



不,两者都会导致默认初始化。你不能在没有kludge的情况下创建一个没有初始化的类对象。


DrX


Hi,
I saw some codes use `new classname'' to get a point to
a new object of classname, but some codes, instead, use
`new classname()''.
Is these two usage equivalent?

Thank you.

--
Hongzheng Wang
Department of Electronics Engineering
Tsinghua University
wa******@mails.tsinghua.edu.cn

解决方案

"Hongzheng Wang" <wa******@mails.tsinghua.edu.cn> wrote...

I saw some codes use `new classname'' to get a point to
a new object of classname, but some codes, instead, use
`new classname()''.
Is these two usage equivalent?



For POD they are not. The former leaves it uninitialised,
the latter makes it default-initialised, IIRC.

Victor



"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:akyzb.416658


Fm2.425058@attbi_s04...

"Hongzheng Wang" <wa******@mails.tsinghua.edu.cn> wrote...

I saw some codes use `new classname'' to get a point to
a new object of classname, but some codes, instead, use
`new classname()''.
Is these two usage equivalent?



For POD they are not. The former leaves it uninitialised,
the latter makes it default-initialised, IIRC.

Victor


No, both would cause default initialization. You cannot create an
uninitialized class object without a kludge.

DrX


这篇关于“new classname”和“new classname()”相同吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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