An overloaded constructor is a constructor which takes arguments. It is also called parameterized constructor.
Example: Example: Here is an example of student class of standard 12. Default Constructor initializes the default name as blank and age of the student as 16. Overloaded constructor has provisions to give name and age as arguments during construction.
#include<string.h> #include<iostream.h> class std12_student { private: int age; char name[20]; public: /*Default Constructor*/ std12_student() { age = 18; strcpy(name, ""); } /*Overloaded Constructor 1*/ std12_student(char *student_name) { age = 18; strcpy(name, student_name); } /*Overloaded Constructor 2*/ std12_student(char *student_name, int student_age) { age = student_age; strcpy(name, student_name); } int get_age() { return age; } char* get_name() { return name; } }; int main(int argc, char* argv[]) { std12_student s("ABC", 17); cout << "Name : " << s.get_name() << "Age = " << s.get_age(); return 0; }
About our authors: Team EQA
You have viewed 1 page out of 62. Your C++ learning is 0.00% complete. Login to check your learning progress.
Most popular
Questions index C Questions C++ Questions Win32 MFC COM/DCOM DLL Questions
Compilers & Editors
Download Visual Studio Download XCode Download Visual Studio Code Android studio install sdk Eclipse installer Best C compilers IDEs
Development system setup
Windows media creation tool MSDN subscription Ubuntu virtualbox
New updated posts
Why learn C? Calculate weighted average
Questions index C Questions C++ Questions Win32 MFC COM/DCOM DLL Questions
Compilers & Editors
Download Visual Studio Download XCode Download Visual Studio Code Android studio install sdk Eclipse installer Best C compilers IDEs
Development system setup
Windows media creation tool MSDN subscription Ubuntu virtualbox
New updated posts
Why learn C? Calculate weighted average