Technical Discussion :: C++
Home > Technical Interview Q&A > C++ > Discussion
76 / 187
What is overloading constructor?
Or
What is multiple constructor?
Answer:
The sharing the same name by two or more functions is referred to as function overloading. Similarly when more than one constructor function is defined in a class. We say that the constructor is overloaded. It is also called multiple constructors.
Example :
Complex() { } //constructor with no arg.
Complex (float a) { x=y=a;} //constructor with one arg.
Complex (float real, float imag) //constructor with two arg.
Asked In ::
Ambrish
23 Feb, 2019 5:07 AM
The sharing the same name by two or more functions is referred to as function overloading. Similarly when more than one constructor function is defined in a class. We say that the constructor is overloaded. It is also called multiple constructors.
Example :
Complex() { } //constructor with no arg.
Complex (float a) { x=y=a;} //constructor with one arg.
Complex (float real, float imag) //constructor with two arg.
Example :
Complex() { } //constructor with no arg.
Complex (float a) { x=y=a;} //constructor with one arg.
Complex (float real, float imag) //constructor with two arg.