educative.io

"&" in the wrong spot for function overloading course in c++?

In the function overloading course, is the & at the wrong space here “min(const int& x, const int& y)”?


Type your question above this line.

Course: https://www.educative.io/collection/10370001/5128982204776448
Lesson: https://www.educative.io/collection/page/10370001/5128982204776448/5661947397668864

Hi @Yuanhao_Zhang

I don’t think that the & used in the min() function parameter list under “Rules for choosing the right function” is wrongly placed.
The author of the course is trying to communicate how function overloading works in C++.
He explains that in C++, passing an argument to a function by value is no different from passing the same argument to the same function by reference (using & in parameter list).

Hi @ Usman_Younas,
Someone learning C++ and haven’t encountered Reference variable and pointers would find it bit tricky and difficult to understand. I think the author should not introduce topics in the examples until they are already taught.