+ 3

Why to use default constructor?whats the use of default constructor?

class sample { int a; public:sample() { a=0; } };

23rd Nov 2016, 3:44 AM
sadiya zainab
sadiya zainab - avatar
3 Respuestas
+ 9
For Initialize variable
18th Mar 2017, 5:02 AM
mr.Frechman
mr.Frechman - avatar
+ 2
default constructor is the non-parameterised construction that is used to assign default values to member variables . it is good practice to use default constructor because if u don't use ur own default constructor then all the class variable will contain garbage values and if used before initialisation they may give unexpected results.
23rd Nov 2016, 6:00 AM
Sumit Singh
Sumit Singh - avatar
0
They are good practice for a scenario for when someone else intends to use or build upon your code in a way that you might not be able to account for.
23rd Nov 2016, 9:13 AM
Andrew Michel
Andrew Michel - avatar