Site icon T4Tutorials.com

Function overloading in C++ and OOP with examples

Function overloading in C++ and OOP with examples

In this tutorial, we will learn about the followings;

What is function overloading?

Function overloading is a technique that allows to define and use more than one functions with the same scope and same name. But each function has a unique, which can be derived from the followings;

  1. argument type
  2. function name
  3. Total number of arguments
  4. Sequence of arguments
  5. Name of arguments
  6. return type.

Example of  Function overloading in C++

#include <iostream>
using namespace std;
void Sum_T4Tutorials(int a, int b)
{
  cout << "sum = " << (a + b);
}
 
void Sum_T4Tutorials(double a, double b)
{
    cout << endl << "sum = " << (a + b);
}
 
// Driver code
int main()
{
    Sum_T4Tutorials(4, 6);
    Sum_T4Tutorials(8.1, 7.4);
    return 0;
}

Output

sum = 10
sum = 15.5

Exit mobile version