Hi guys,
I want to make a program but I wanted to know that when should we use overloaded constructor?
The default constructor can do the job?Code:class Vehicle { private: string Name; int reg_no; public: Vehicle() void getName(); void setName(); ~Vehicle() };
The default constructor automatically initializes an object which is created ,so what is the use of overloaded constructor?
Also have I written the constructor correctly?
I hope I am clear
Thanks



1Likes
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. 