Hello,
Implicit default ctor does not initialize the built-in data members, so what is it needed for?
Thanks.
Printable View
Hello,
Implicit default ctor does not initialize the built-in data members, so what is it needed for?
Thanks.
You mean the default c'tor (i.e. the one that takes no parameters) that the compiler creates for your class automatically (i.e. by default) if you don't define one yourself? And by "built-in data members" that don't get initialized by it you mean member variables of your class that are of POD types like int? This default-created default c'tor simply calls the default c'tors of member variables of your class that are of non-POD class types like, for instance std::string, as well as any potential default c'tors of your class' base classes.
I see, thank you.
I agree with Eri. But still the question is on its place as why the default constructor is added by default. What is its role.
Think that I have all the POD attributes then what is the use?
Also if the we see recursively(it calls the default of the base and the same question is arised for the base's default constructor now)
So that, if applicable, you can create an object without having to explicitly define a constructor.
Thanks laser.
Now it seems to be correctly resolved thread