【问题标题】:What is the difference between these two C++ statements? [duplicate]这两个 C++ 语句有什么区别? [复制]
【发布时间】:2011-04-10 08:17:12
【问题描述】:

可能重复:
Do the parentheses after the type name make a difference with new?

在C++中,这两个语句有什么区别?

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;

}

【问题讨论】:

标签: c++ syntax constructor initialization new-operator


【解决方案1】:

实际上?没什么,一堂课。

在底层,一个调用类的显式构造函数,而另一个调用默认构造函数。在任何情况下,你的两个构造函数都有可能做同样的事情(在上述情况下,它们会做同样的事情,尽管理论上你可以调用复制构造函数),但对于 POD 类型来说并非如此。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-04-16
    • 2022-01-02
    • 1970-01-01
    • 1970-01-01
    • 2023-03-15
    • 2015-05-31
    • 2020-11-01
    相关资源
    最近更新 更多