Overload functions with two parameters : function overload « Function « C++ Tutorial






#include <iostream>  
using namespace std;  
 
int min(int a, int b);     // min() for ints 
char min(char a, char b);  // min() for chars 
int * min(int *a, int *b); // min() for int pointers 
 
int main()  
{  
  int i=10, j=22; 
 
  cout << "min('X', 'a'): " << min('X', 'a') << "\n"; 
  cout << "min(9, 3): " << min(9, 3) << "\n"; 
  cout << "*min(&i, &j): " << *min(&i, &i) << "\n"; 
  
  return 0;  
} 
 
// min() for ints.  Return the smallest value. 
int min(int a, int b) 
{ 
  if(a < b) return a; 
  else return b; 
} 
 
// min() for chars -- ignore case. 
char min(char a, char b) 
{ 
  if(tolower(a) < tolower(b)) return a; 
  else return b; 
} 
 
/* 
   min() for int pointers.  
   Compare values and return pointer to smallest value. 
*/ 
int * min(int *a, int *b) 
{ 
  if(*a < *b) return a; 
  else return b; 
}
min('X', 'a'): a
min(9, 3): 3
*min(&i, &j): 10








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