开发者

Not using parentheses in constructor call with new (c++) [duplicate]

This question already has answers here: 开发者_如何学运维 Closed 11 years ago.

Possible Duplicate:

Do the parentheses after the type name make a difference with new?

So I had in my main:

Class* pC = new Class;

It was working as

Class* pC = new Class();

I realized just today that I had omitted the parentheses (so I was hit by the "opposite" of the most vexing parse in a way).

My question: Are these two forms equivalent ?


If the class has a default constructor defined, then both are equivalent; the object will be created by calling that constructor.

If the class only has an implicit default constructor, then there is a difference. The first will leave any members of POD type uninitialised; the second will value-initialise them (i.e. set them to zero).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜