overloading

Function Overloading

While writing a class when we write two or more functions with same name, but they have different parameters or arguments is called Function Overloading.

 

#include <iostream>
using namespace std;
class Geeks {
    public:
    void func(int x)     {         
        cout << "value of x is " << x << endl;
    }
    void func(double x){           
        cout << "value of x is " << x << endl;
    }
    void func(int x, int y) { 
        cout << "value of x and y is " << x << ", " << y << endl;
    }
};

int main() {
    Geeks obj1;     
    obj1.func(7);       
    obj1.func(9.132);            
    obj1.func(85,64);        
    return 0;
} 

Leave a Reply

Your email address will not be published. Required fields are marked *