Hi Guys,
I wanted to know that can we have default constructor and also a parameterized constructor for the same class ?
eg:
----------------------------------Code:---------------------------- class Student { private: char Name; int age; public: Student(); //default constructor/ Student(char Name ,int age) //constructor with parameters/ void getName(); void getage(); };
Have I written the parameterized constructor correctly?
Thanks



2Likes
LinkBack URL
About LinkBacks




Technically, unless copy constructors (that create an object from an existing object of the same type) are disabled, all constructors are overloaded. The compiler will generate a copy constructor if the programmer doesn't, and it can. It doesn't make sense to have a copy constructor unless there is some other way to create an object to be copied - which means another overloaded constructor must exist. The only exceptions to this are if copy constructors are specifically suppressed.