Overload function by parameter type: int, double and long : function overload « Function « C++ Tutorial






#include <iostream>  
using namespace std;  
 
int neg(int n);       // neg() for int. 
double neg(double n); // neg() for double. 
long neg(long n);     // neg() for long. 
 
 
int main()  
{  
 
  cout << "neg(-10): " << neg(-10) << "\n"; 
  cout << "neg(9L): " << neg(9L) << "\n"; 
  cout << "neg(11.23): " << neg(11.23) << "\n"; 
  
  return 0;  
} 
 
// neg()for int. 
int neg(int n) 
{ 
  return -n; 
} 
 
// neg()for double. 
double neg(double n) 
{ 
  return -n; 
} 
 
// neg()for long. 
long neg(long n) 
{ 
  return -n; 
}
neg(-10): 10
neg(9L): -9
neg(11.23): -11.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