Search code examples
c++constructordefault-constructordefault-arguments

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


In the following code:

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

Does the constructor count as a default constructor?


Solution

  • 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.