Functions that can’t be overloaded in C++


In C++, we can overload the functions. But sometimes the overloading is not done. In this section, we will see what are the different cases, in which we cannot overload the functions.

  • When function signatures are same, only the return type is different, then we cannot overload the function.

int my_func() {
   return 5;
}
char my_func() {
   return 'd';
}
  • When the member functions have the same name and same parameter list in a class, then they cannot be overloaded.

class My_Class{
   static void func(int x) {
      //Something
   }
   void func(int x) {
      //something
   }
};
  • When the parameter declaration, that differs only in a pointer * and an array [] are same.

int my_func(int *arr) {
   //Do something
}
int my_func(int arr[]) {
   //do something
}
  • When the parameter declaration, that differs only in a presence of constant or volatile qualifier are same.

int my_func(int x) {
   //Do something
}
int my_func(const int x) {
   //do something
}
  • When the parameter declaration, that differs only in their default arguments are equivalent.

int my_func(int a, int b) {
   //Do something
}
int my_func(int a, int b = 50) {
   //do something
}

Updated on: 30-Jul-2019

237 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements