codegurukool.com · Free coding tutorials & online compiler

Home › C++ Tutorial › C++ function overloading

C++ function overloading

Same name, different parameters.

The compiler picks the version by argument types or count.

Example code

#include <iostream>
using namespace std;
int twice(int x) { return x * 2; }
double twice(double x) { return x * 2.0; }
int main() {
  cout << twice(4) << " " << twice(2.5) << endl;
  return 0;
}

Run this code in the online editor

← C++ functions and parametersC++ scope →