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.
4 Respuestas
+ 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.
+ 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
0
Thank you for this clarification. I didn't know that in prototypes the variables for the arguments might be omitted.
0
thank you very much!!