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!
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!
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 classX
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 classX
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.