In C++, is a constructor with only default arguments a default constructor?

断了今生、忘了曾经 提交于 2019-11-27 03:56:50

问题


In the following code:

struct Foo
{
    Foo(int x=0);
};

Does the constructor count as a default constructor?


回答1:


C++98 §12.1/5 (emphasis mine):

A default constructor for a class X is a constructor of X that can be called without an argument. If there is no user-declared constructor for class X, a default constructor is implicitly declared.

So yes, it does count as a default constructor. See also.



来源:https://stackoverflow.com/questions/11250690/in-c-is-a-constructor-with-only-default-arguments-a-default-constructor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!