All About C++

Get Pure Concepts of C++

Tuesday 1 March 2016

What is function overloading is C++ with code example

Function overloading is C++

In function overloading two or more different functions share exactly the same name. That is because in C++  a function is identified by its signature which comprises both the function's name and the list of arguments it takes. Hence the following code is perfectly fine.

#include <iostream>

using namespace std;
void add_some(int y)
{ y += 3;
cout << y << endl;
}
void add_some(double x)
{ x += 1.5;
cout << x << endl;
}
void main() {
      int a=10;
      double b=11.23;
      add_some(a);
      add_some(b);
      system("pause");
}

This is a simple code to understand the concept of function overloading.


No comments:

Post a Comment