Is overloading compatible with default values in C++ or Java? | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 1

Is overloading compatible with default values in C++ or Java?

I guess no (causing ambiguity) and test it with some codes but still not sure.

20th Dec 2017, 6:06 AM
Bo Yang
Bo Yang - avatar
1 Antwort
+ 1
It is allowed in general, but just like constructors, ambiguity knocks out the rare cases. But cases like these are allowed: void print() { cout<<2<<endl; } void print(int k, char c = 'a') { cout<<k<<" "<<c<<endl; }
20th Dec 2017, 9:53 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar