About function overloading?

what is function overloading ?and what is the difference between function overloading and constructor overloading?

Hello @17manishms,

Function overloading is a feature in C++ where two or more functions can have the same name.
These functions differ by:

  1. No. of parameters passed.
  2. Type of parameters passed.
  3. Order of parameters passed.

At the time of function call, the compiler maps the appropriate function definition with the function call.
Example:

  1. void fun1(int a){}
  2. void fun1(char a){}
  3. void fun1(int a, int b){}
  4. void fun1(int a, float b){}
  5. void fun1(float a, int b){}

Calls:

  1. fun1(2)
    //1. function 1 will be called.
  2. fun1(‘A’)
    //function 2 will be called.
  3. fun1(1,2)
    //function 3 will be called.
  4. fun1(1,2.1)
    //function 4 will be called.
  5. fun1(2.1,1)
    //function 5 will be called.

What is constructor?
A special function which is used to initialize the data members of the class.

What is constructor overloading?
It is a type of function overloading where the function that has been overloaded is a constructor.

How can we overload it?
By using different types of constructors for a class.

Types?

  1. Default
    //With no parameters
  2. Parameterized
    //With parameters
  3. Copy constructor

Hope, this would help.
Give a like if you are satisfied.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.