+ 1

Default constructor vs default argument

Can someone explain why this code produces no output? And also, why is it when I create an object with parentheses instead it gives an error instead? https://code.sololearn.com/cfPBOo2J4B0Q/?ref=app

8th Jun 2022, 5:27 AM
Edward Finkelstein
Edward Finkelstein - avatar
4 Antworten
+ 2
About creating the object using empty parenthesis, I found this: https://stackoverflow.com/a/181463
8th Jun 2022, 11:21 AM
Emerson Prado
Emerson Prado - avatar
+ 3
The overloaded constructor has a parameter, but it has a default value, so it's optional. Being optional, it means the second constructor accepts being called with no arguments - which the first one accepts too, so the redundance error.
8th Jun 2022, 11:10 AM
Emerson Prado
Emerson Prado - avatar
0
Emerson Prado huh that is interesting, I wouldn’t have guessed that, thanks for the link!
8th Jun 2022, 11:40 AM
Edward Finkelstein
Edward Finkelstein - avatar