New course! Every coder should learn Generative AI!
Try a free lesson0
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); }
2 Answers
+ 1
https://www.sololearn.com/learn/CPlusPlus/1640/
You have different parameters for each of these.
+ 1
thanks Jonas!