0

Bug in the code snippet - operator overloading, second question.

In the operator overloading section, the code snippet in the second question is wrong. The class has two constructors. One without any parameters and a second one with an integer parameter. In the second one in the brackets there is space for entering the "int" keyword, a name for the parameter variable is missing, which is the mistake in the code snippet.

18th Jul 2016, 12:45 PM
Svilen Pavlov
Svilen Pavlov - avatar
4 odpowiedzi
+ 3
the code snippet is fine. this is called function prototyping, it simply tells the compiler that this function exists with these parameters. for example: int myFunc (int); int main () {int x = 5; cout <<myFunc (x); return 0; } int myFunc(int myInt) {return myInt;} we gave the definition of myFunc after int main, but we can still use it because we prototyped it before int main. so all we did was tell the compiler that there's a function somewhere called myFunc that takes an integer as a parameter.
18th Jul 2016, 8:40 PM
destro
+ 1
sure thing! and you can also name them in the prototype but it's just faster to give the datatype since you have to name it again anyways
18th Jul 2016, 8:56 PM
destro
0
Thank you for this clarification. I didn't know that in prototypes the variables for the arguments might be omitted.
18th Jul 2016, 8:52 PM
Svilen Pavlov
Svilen Pavlov - avatar
0
thank you very much!!
25th Jul 2016, 2:53 PM
Davide Jako Albieni
Davide Jako Albieni - avatar