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.





