C++ Function Overloading

PREV     NEXT

What is function overloading?

  • Overloading means the use of the same thing for different purposes. Function Overloading is a most important feature of C++ in which two or more functions can have the same name but different parameters or arguments for the different tasks.
  • It is known as function polymorphism in OOP. By using the concept of function overloading we can create a family of functions with one function name but with different parameters or arguments.
  • The function will perform different operations but on the basis of the argument list in the function call.

Let us have a look at the syntax:

int test ( ) { }

int test ( int x) { }

int test ( int x, double y) { }


double test ( double a) { }

Different ways to overload a function

The function overloading can be done in two ways:

  • Having different types of argument
  • Changing number of arguments.

Having different types of arguments:

In function overloading we can define two or more functions with same name and same number of arguments but the type of the argument is different.


Let us have a look at the example:

COMPILE & RUN

Number of different arguments:

In this type we define two functions with same names but with different number of arguments of the same type. Let us have a look at the example:

COMPILE & RUN

Let us have a look at the example to better understand the concept of function overloading:

COMPILE & RUN

PREV     NEXT

Share this website !!!
Facebook Twitter Linkedin