0

Does the following one-parameter constructor also serve as a default constructor?

class SomeClass
    {
    public:
        SomeClass(const int &a = 4);
    }

(Assuming the constructor is well defined etc.)

Thanks!

1 Answers1

4

Yes, the definition of default constructor allows parameters as long as they have default values:

A default constructor for a class X is a constructor of class X for which each parameter that is not a function parameter pack has a default argument (including the case of a constructor with no parameters).

(from the C++1z draft)

Older phrasing:

A default constructor for a class X is a constructor of class X that can be called without an argument.


In addition, your copy constructor will be implicitly defined as defaulted, because you haven't declared one.

There is no such thing as a "default copy constructor". But "default constructor" and "defaulted copy constructor" are meaningful.

Ben Voigt
  • 277,958
  • 43
  • 419
  • 720
  • @HolyBlackCat: Also, the standard wording is somewhat more reliable than cppreference. A couple times the cppreference paraphrase has changed the meaning in an important way. – Ben Voigt Sep 05 '18 at 15:17
  • 1
    ... and this is why we use `explicit`, to guard against unintended conversions – Tim Randall Sep 05 '18 at 15:50