Function Overloading is a process in which we define a function with same name but their arguments (parameters) are different according to the data types . Function can also be overload with increasing or decreasing the number of arguments in a function. Remember Compiler choose the function according to the input when it deal with overloaded functions.
Source Code
#include<iostream> using namespace std; class Function_overloading { public: void calculate (int a,int b) { cout<<" SUM IS : " <<a+b; } void calculate (double a,double b) { cout<<" SUM IS : " <<a+b; } void calculate (float a,float b) { cout<<" SUM IS : " <<a+b; } }; int main () { Function_overloading f; f.calculate(24,45); cout<<endl; f.calculate(45.3,67.68); cout<<endl; f.calculate(1234567,7654321); }
0 comments:
Post a Comment