Function overloading that differs in return type not necessarily throws an error? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Function overloading that differs in return type not necessarily throws an error?

The below code has 3 different return types for same function name and runs with no error. #include <iostream> using namespace std; int printNumber(int y) { cout << "Prints an integer: " << y << endl; } float printNumber(float x) { cout << "Prints a float: " << x << endl; } double printNumber(int x, int y){ cout << "Prints a double: " << x + y << endl; } int main() { int a = 16; float b = 54.541; printNumber(a); printNumber(b); printNumber(a,b); }

9th Mar 2018, 6:22 AM
Sreenidhi
Sreenidhi - avatar
2 Answers
+ 1
https://www.sololearn.com/learn/CPlusPlus/1640/ You have different parameters for each of these.
9th Mar 2018, 6:42 AM
Jonas Schröter
Jonas Schröter - avatar
+ 1
thanks Jonas!
9th Mar 2018, 10:01 AM
Sreenidhi
Sreenidhi - avatar