开发者

What is the difference between these two C++ statements? [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

Do th开发者_JAVA技巧e parentheses after the type name make a difference with new?

In C++, what is the difference between these two statements?

Class clg
{

  public :

  int x,y,z;

};

int main(void)

{

  clg *ptrA = new clg;    //

  clg *ptrB = new clg();  //  what is the importance of "()"  ???

 return 0;

}


Practically? Nothing, for a class.

Under the hood, one calls an explicit constructor of the class, whereas the other calls the default constructor. In any case, chances are both your constructors will do the same thing(in the above case, they will, though you could theoretically call the copy constructor), though this is not true for POD types.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜