Generic functions perform the same operation for all the versions of a function except the data type differs. Let’s see a simple example of an overloaded function which cannot be replaced by the generic function as both the functions have different functionalities.
Example:
#include <iostream>
using namespace std;
void fun(double a)
{
cout<<"value of a is : "<<a<<'\n';
}
void fun(int b)
{
if(b%2==0)
{
cout<<"Number is even";
}
else
{
cout<<"Number is odd";
}
}
int main()
{
fun(4.6);
fun(6);
return 0;
}
/*
Output :
value of a is : 4.6
Number is even
*/
In the above example, we overload the ordinary functions. We cannot overload the generic functions as both the functions have different functionalities. First one is displaying the value and the second one determines whether the number is even or not..