Function overloading is a feature that allows multiple functions to have the same name with different parameters. The compiler determines which function to invoke based on the number and type of arguments passed.
#include <iostream>
using namespace std;
class Printer {
public:
void print(int i) {
cout << "Integer: " << i << endl;
}
void print(double d) {
cout << "Double: " << d << endl;
}
void print(string s) {
cout << "String: " << s << endl;
}
};
int main() {
Printer printer;
printer.print(10); // Calls print(int)
printer.print(3.14); // Calls print(double)
printer.print("Hello"); // Calls print(string)
return 0;
}