Function Overloading
#include <stdafx.h>
#include <iostream>
#include <string>
using namespace std;
/* Function overloading is the re definition of a function with same name but
difference in number of arguments or type of arguments or return type. */
class BaseClass
{
public :
void display()
{
cout<< "display function with no parameter" << endl;
}
void display(int i)
{
cout<< "display function receiving integer parameter " << i << endl;
}
void display(int i,string message)
{
cout<< "display function receiving integer parameter " << i << " and string parameter "<< message << endl;
}
};
int main()
{
cout<< "Example of overloading" << endl;
BaseClass ch;
ch.display();
ch.display(100);
ch.display(100,"hai");
return 0;
}
Output:
Example of overloading
display function with no parameter
display function receiving integer parameter 100
display function receiving integer parameter 100 and string parameter hai