In C++, how will the compiler distinguish between overloaded functions and functions with default values for the arguments | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

In C++, how will the compiler distinguish between overloaded functions and functions with default values for the arguments

for example if I have two overloaded methods, one takes only one integer (e.g: myfunc(int var) ), and the other one takes two integers with default values (e.g: myfunc(int var, int varr = 3) ). and when I call them in the main() I pass only one parameter! (e.g: myfunc(5); )...which one will be called? the one with one argument or the other one and it will consider the other integer with its default value?! and why?

5th Feb 2017, 12:27 PM
Tasneem Mabrouk
Tasneem Mabrouk - avatar
4 Answers
+ 1
sorry, I didn't understand 💔
5th Feb 2017, 9:03 PM
Tasneem Mabrouk
Tasneem Mabrouk - avatar
+ 1
I've just edited the description of the question to make it clear if it was'nt :)
5th Feb 2017, 9:08 PM
Tasneem Mabrouk
Tasneem Mabrouk - avatar
0
iirc you would have to do function(varName, int) for the default value to come out.
5th Feb 2017, 8:38 PM
Phil Marinucci
Phil Marinucci - avatar
0
if you pass it a blank value it should access the default
5th Feb 2017, 9:05 PM
Phil Marinucci
Phil Marinucci - avatar