Table of contents
1.
Introduction
2.
Cases where Function Overloading isn’t possible
3.
Frequently Asked Questions
3.1.
Is function overloading and function overriding the same?
3.2.
Is function overloading a feature of OOPs only?
3.3.
What feature is used to implement function overloading?
4.
Conclusion
Last Updated: Mar 27, 2024
Easy

Functions that can’t be overloaded

Author Ayushi Poddar
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

Object-oriented programming has a function overloading feature, which allows two or more functions that can have the same name but will have distinct parameters. Function Overloading occurs when a function name is overloaded with several jobs. The arguments passed as parameters should differ but the function name should be the same in function overloading. Polymorphism is a feature of C++ and object-oriented programming that can be used to overload functions.

But there are certain specific cases where function overloading cannot be implemented. Let’s discuss those cases.

Cases where Function Overloading isn’t possible

Following function declarations in C++ are not allowed to be overloaded.

  • If one of these functions is a static member function declaration, member function declarations with the same name and the name parameter-type list cannot be overloaded. For example:
class My_Example{
   static void funct(int x) {
      —-------------
   }
   void funct(int x) {
    —-------------
   }
};


You can also practice with the help of Online C++ Compiler

  • The sole difference between the two-parameter declarations is that one is a function type(void h(int ())) and the other one is a pointer to the same function type (void h(int ())). For example:
void h(int ());
void h(int (*)());

 

  • The function cannot be overloaded when the function signatures are identical except for the return type. For example:
#include<iostream>
int fUNC() { 
  return 47; 
}  
char fUNC() { 
  return 'a'; 
}

 

  • The only difference between a pointer * and an array [] is the type of parameter declaration. In other words, the array declaration is changed to a pointer declaration. Only the second and subsequent array dimensions matter in terms of parameter types. For example :
#include<iostream>
#include<stdio.h>
using namespace std;
int func( int x) {
    return x+10;
} 
int func( const int x) {
    return x+10;
}

 

  • The sole difference between the two-parameter declarations is their default parameters. For example:
#include<iostream>
#include<stdio.h>   
using namespace std;   
int func ( int x, int y) {
    return x+10;
}  
int func ( int x, int y = 47) {
    return x+y; 
    }

 

Check out this article - Compile Time Polymorphism, Difference between argument and parameter.

Frequently Asked Questions

Is function overloading and function overriding the same?

No, they are not the same. Function overriding is redefining a base class function in a derived class with the same signature, that is, the return type and parameters.

Is function overloading a feature of OOPs only?

Yes, function overloading is only a feature of Object-Oriented Programming language.

What feature is used to implement function overloading?

Polymorphism is a feature of C++ that can be used to overload functions.

Conclusion

This article discussed the different cases where we cannot implement function overloading in C++, an essential feature of Object-Oriented Programming Language. We hope this blog has helped you gain more knowledge about the discussed topic. Check out our articles on Coding Ninjas.

Refer to our Guided Path on Coding Ninjas Studio to upskill yourself in Data Structures and AlgorithmsCompetitive ProgrammingFunctionsSystem Design, and many more! If you want to test your competency in coding, you may check out the mock test series and participate in the contests hosted on Coding Ninjas Studio! But suppose you have just started your learning process and are looking for questions from tech giants like Amazon, Microsoft, Uber, etc. In that case, you must look at the problemsinterview experiences, and interview bundle for placement preparations.

Nevertheless, you may consider our paid courses to give your career an edge over others!

Do upvote our blogs if you find them helpful and engaging!

Live masterclass