在 C++ 中,只有默认参数的构造函数是默认构造函数吗?
在以下代码中:
struct Foo
{
Foo(int x=0);
};
构造函数算作默认构造函数吗?
Does the constructor count as a default constructor?
推荐答案
C++98 §12.1/5 (强调我的):
C++98 §12.1/5 (emphasis mine):
类 X 的默认构造函数是无需参数即可调用的 X 构造函数.如果类 X 没有用户声明的构造函数,则隐式声明默认构造函数.
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.
相关文章