Method Overloading - heshawacooray/OOP-Heshawa GitHub Wiki

Definition: Method overloading allows a class to have multiple methods with the same name but different parameters. The correct method is selected based on the number or type of arguments passed.

Example code:

#include <iostream>
using namespace std;

class Printer {
public:
    void print(int i) {
        cout << "Printing integer: " << i << endl;
    }

    void print(string str) {
        cout << "Printing string: " << str << endl;
    }
};

int main() {
    Printer p;
    p.print(5);       // Calls print(int)
    p.print("Hello"); // Calls print(string)

    return 0;
}
⚠️ **GitHub.com Fallback** ⚠️