Overload a function three times. : function overload « Function « C++ Tutorial






#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








7.12.function overload
7.12.1.Overload a function three times.
7.12.2.Overload function by parameter type: int, double and long
7.12.3.Overload functions with two parameters
7.12.4.Overloading functions with difference in number of parameters
7.12.5.Create overloaded print() and println() functions that display various types of data
7.12.6.Overload function with array type
7.12.7.Overloading a function with const reference parameters
7.12.8.Overloading a function with reference parameters
7.12.9.Default Arguments vs. Overloading
7.12.10.Finding the Address of an Overloaded Function