Overload function: int and float
#include <iostream>
using namespace std;
int difference(int a, int b)
{
return a-b;
}
float difference(float a, float b)
{
return a-b;
}
int main()
{
int (*p1)(int, int);
float (*p2)(float, float);
p1 = difference; // address of difference(int, int)
p2 = difference; // address of difference(float, float);
cout << p1(10, 5) << ' ';
cout << p2(10.5, 8.9) << '\n';
return 0;
}
Related examples in the same category