- Hongzheng Wang 电子工程系 清华大学 wa ****** @ mails.tsinghua.edu.cn 解决方案 " Hongzheng Wang" < WA ****** @ mails.tsinghua.edu.cn>写道... 我看到一些代码使用`new classname''来指向一个新的classname对象,但有些代码使用了`new classname()''。这两个用法是否相同? 对于POD,它们不是。前者没有初始化, 后者默认初始化,IIRC。 Victor " 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 toa new object of classname, but some codes, instead, use`new classname()''.Is these two usage equivalent?Thank you.--Hongzheng WangDepartment of Electronics EngineeringTsinghua 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 messagenews:akyzb.416658Fm2.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. VictorNo, both would cause default initialization. You cannot create anuninitialized class object without a kludge.DrX 这篇关于“new classname”和“new classname()”相同吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-19 09:41
查看更多