Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

about implicit constructor creation?

it's well knows that compiler implicitly creates an constructor but if we have a code like this:

class A
{
    public:
       A(int = 0) {}

};

this constructor is default one and conversion operator in same time.

Question:

will compiler generate "empty" default constructor A() {} anyway as well?

like image 324
codekiddy Avatar asked Feb 04 '26 04:02

codekiddy


1 Answers

No. A default constructor is one that has no arguments or arguments with default values.

So, basically, you already defined the default constructor.

Section 12.1.5 from C++03 states this:

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

As you can call your constructor without an argument, it is a default one. Ergo, the compiler doesn't need to declare another.

like image 122
Luchian Grigore Avatar answered Feb 05 '26 18:02

Luchian Grigore



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!