Mega Code Archive

 
Categories / C++ Tutorial / Function
 

Overload a function three times

#include <iostream>  using namespace std;    void f(int i);         void f(int i, int j);  void f(double k);        int main()  {    f(10);     // call f(int)      f(10, 20); // call f(int, int)      f(12.23);  // call f(double)      return 0;  }    void f(int i)  {    cout << "In f(int), i is " << i << '\n';  }    void f(int i, int j)  {    cout << "In f(int, int), i is " << i;    cout << ", j is " << j << '\n';  }    void f(double k)  {    cout << "In f(double), k is " << k << '\n';  } In f(int), i is 10 In f(int, int), i is 10, j is 20 In f(double), k is 12.23