Function Overloading - heshawacooray/OOP-Heshawa GitHub Wiki
Definition: Function overloading allows a class to have multiple functions with the same name but different parameters (i.e., different number or types of arguments). The compiler will choose the correct function based on the function signature (parameters).
Example code:
#include <iostream>
using namespace std;
class Print {
public:
void display(int i) {
cout << "Integer: " << i << endl;
}
void display(double d) {
cout << "Double: " << d << endl;
}
void display(string str) {
cout << "String: " << str << endl;
}
};
int main() {
Print p;
p.display(5); // Calls display(int)
p.display(3.14); // Calls display(double)
p.display("Hello"); // Calls display(string)
return 0;
}