Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 969
Matt Avatar asked Jun 28 '12 18:06

Matt


1 Answers

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.

like image 143
BlueRaja - Danny Pflughoeft Avatar answered Nov 13 '22 04:11

BlueRaja - Danny Pflughoeft