why do we need a constructor as a class member
Answers
Answered by
6
Constructor is a special memberfunction which has same name asclass name and called whenever object of that class is created. Theyare used to initialize data field in object. ... Constructor can be overloaded. Default constructor isautomatically created when compiler does not find any constructor in aclass.
Answered by
1
Explanation:
- Whenever an object is created, it must be constructed usually with legal initial values automatically without being specified by the programmer. This will immensely relieve the programmer from initializing values of objects for large programs and hence the need for constructor.
Constructor:
- Constructor is a function that have the same name as the class and is automatically invoked during creation of an object.
Similar questions