0

Overloaded Functions with Default Parameter Values

Say I have 2 methods with the same name, one that takes two int parameters while the other takes three int parameters. If i give all but the first parameter a default value and then call the method, passing just one argument, how would the compiler handle this? Would this action be illegal or just confuse the compiler. Inb4 This lesson said different type and/OR number of parameters warrants an overloaded function.

1st May 2018, 12:20 AM
Domingo Gonzales III
4 Respostas
+ 3
can you please give an example?
4th May 2018, 5:23 PM
$¢𝐎₹𝔭!𝐨𝓝
$¢𝐎₹𝔭!𝐨𝓝 - avatar
+ 2
Hi The Great Saga (idol)! Thanks for the reply. I was thinking something like this: void test(int a) { cout << '1'; } void test(int a, int b = 2) { cout << '2'; }
6th May 2018, 12:04 PM
Domingo Gonzales III
+ 2
Ahh, that makes sense. Not illegal but doesn't make sense to the compiler. Thanks Shivam!
11th May 2018, 5:09 PM
Domingo Gonzales III
+ 1
it will confuse the compiler and will result into ambiguity for the function
11th May 2018, 1:16 PM
Shivam Papat
Shivam Papat - avatar