C++ Function Overloading C-PLUS-PLUS

C++ Function Overloading  

C++ Function Overloading

C++ Function Overloading

Multiple functions can have the same name with different parameters, is known as function overloading.

Example

#include <iostream>
using namespace std;

int plusFunc(int x, int y) {
  return x + y;
}

double plusFunc(double x, double y) {
  return x + y;
}

int main() {
  int myNum1 = plusFunc(3, 6);
  double myNum2 = plusFunc(4.3, 6.26);
  cout << "Int: " << myNum1 << "\n";
  cout << "Double: " << myNum2;
  return 0;
}
 

Output:

Int: 9
Double: 10.56

Download free E-book of C-PLUS-PLUS


#askProgrammers
Learn Programming for Free


Join Programmers Community on Telegram


Talk with Experienced Programmers


Just drop a message, we will solve your queries