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.
4 Answers
+ 3
can you please give an example?
+ 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';
}
+ 2
Ahh, that makes sense. Not illegal but doesn't make sense to the compiler. Thanks Shivam!
+ 1
it will confuse the compiler and will result into ambiguity for the function