Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App

Related Articles

Advantages and Disadvantages of Function Overloading in C++

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

Function overloading is one of the important features of object-oriented programming. It allows users to have more than one function having the same name but different properties. Overloaded functions enable users to supply different semantics for a function, depending on the signature of functions.

Advantages of function overloading are as follows:

  • The main advantage of function overloading is that it improves code readability and allows code reusability.
  • The use of function overloading is to save memory space, consistency, and readability.
  • It speeds up the execution of the program
  • Code maintenance also becomes easy.
  • Function overloading brings flexibility to code.
  • The function can perform different operations and hence it eliminates the use of different function names for the same kind of operations.

Disadvantage of function overloading are as follows:

  • Function declarations that differ only in the return type cannot be overloaded


int fun();
float fun();

 It gives an error because the function cannot be overloaded by return type only.

  • Member function declarations with the same name and the same parameter types cannot be overloaded if any of them is a static member function declaration.
  • The main disadvantage is that it requires the compiler to perform name mangling on the function name to include information about the argument types.



// Importing input output stream files
#include <iostream>
using namespace std;
// Methods to print
// Method 1
void print(int i)
    // Print and display statement whenever
    // method 1 is called
    cout << " Here is int " << i << endl;
// Method 2
void print(double f)
    // Print and display statement whenever
    // method 2 is called
    cout << " Here is float " << f << endl;
// Method 3
void print(char const* c)
    // Print and display statement whenever
    // method 3 is called
    cout << " Here is char* " << c << endl;
// Method 4
// Main driver method
int main()
    // Calling method 1
    // Calling method 2
    // Calling method 3
    return 0;


 Here is int 10
 Here is float 10.1
 Here is char* ten

Output Explanation:

In the above example all functions that were named the 3 same but printing different to which we can perceive there were different calls been made. This can be possible because of the arguments been passed according to which the function call is executed no matter be the functions are sharing a common name. Also, remember we can overload the function by changing their signature in return type. For example, here boolean print() function can be called for all three of them.

My Personal Notes arrow_drop_up
Last Updated : 23 Mar, 2021
Like Article
Save Article
Similar Reads