Will default constructor still be created if I explicitly define a constructor with arguments but no default constructor?
Thank you!
No, you have to explicitly provide the default constructor in that case.
Although you can (from C++11 onwards), for a class Foo, use the syntax
Foo() = default;
within the class declaration which reintroduces the compiler-generated default constructor. (Note you need to put this in the public section for exact equivalence).
Alternatively, if you provide default arguments to all the constructor parameters, then it becomes the default constructor.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With