+ 1
Regarding a question in a lesson of C++ course named "Operator Overloading"
I guess the question has a bug. The question was: "Fill in the blanks to declare a class ''Sally'', with two constructors, one default constructor (without parameters), and a constructor with one integer parameter." _____ Sally { _____ : Sally(); Sally(_____); }; Here Sally's second constructor should take an integer parameter. Though, the question accepts only when I write "int" in the parameter, I mean, with any variable name; likewise, "int i". When I try to write it properly, it shows wrong answer. Please fix this. Thank you.
2 ответов
+ 3
From the comments of that question.
"Variable name of the constructor's parameter is absent."
Answers:
- An absent parameter name can be used when the actual variable's value is not required. This is useful when overloading parent functions.
- The name of the parameter isn't part of the method's signature, so there is no need to declare it specifically.
Only count, type and order of parameters matter, i.e. for overloading. For implementing the method on the other hand the name is obviously essential.
+ 2
Thank you Diego