Overload function: int and float : Function Overloaded « Function « C++






Overload function: int and float

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

1.Functions differ in number of parametersFunctions differ in number of parameters
2.Overload abs() three waysOverload abs() three ways
3.Overload function: int and longOverload function: int and long
4.Create three functions called prompt( ) that perform this task for data of types int, double, and long
5.Overload function to accept integer or char * argumentOverload function to accept integer or char * argument
6.Overload the min() function.Overload the min() function.
7.Compute area of a rectangle using overloaded functions.Compute area of a rectangle using overloaded functions.
8.function overloading between int and string type