what is function overloading ?and what is the difference between function overloading and constructor overloading?
About function overloading?
Hello @17manishms,
Function overloading is a feature in C++ where two or more functions can have the same name.
These functions differ by:
- No. of parameters passed.
- Type of parameters passed.
- Order of parameters passed.
At the time of function call, the compiler maps the appropriate function definition with the function call.
Example:
- void fun1(int a){}
- void fun1(char a){}
- void fun1(int a, int b){}
- void fun1(int a, float b){}
- void fun1(float a, int b){}
Calls:
- fun1(2)
//1. function 1 will be called. - fun1(‘A’)
//function 2 will be called. - fun1(1,2)
//function 3 will be called. - fun1(1,2.1)
//function 4 will be called. - 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?
- Default
//With no parameters - Parameterized
//With parameters - 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.