+ 3
Why to use default constructor?whats the use of default constructor?
class sample { int a; public:sample() { a=0; } };
3 Antworten
+ 9
For Initialize variable
+ 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.
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.