-
April 16th, 2013, 06:00 PM
#1
[RESOLVED] Implicit default ctor - what is it for?
Hello,
Implicit default ctor does not initialize the built-in data members, so what is it needed for?
Thanks.
-
April 16th, 2013, 08:13 PM
#2
Re: Implicit default ctor - what is it for?
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.
Last edited by Eri523; April 16th, 2013 at 08:16 PM.
I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.
This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.
-
April 16th, 2013, 08:35 PM
#3
Re: Implicit default ctor - what is it for?
-
April 22nd, 2013, 05:26 AM
#4
Re: Implicit default ctor - what is it for?
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)
-
April 22nd, 2013, 05:48 AM
#5
Re: [RESOLVED] Implicit default ctor - what is it for?
So that, if applicable, you can create an object without having to explicitly define a constructor.
-
April 22nd, 2013, 05:53 AM
#6
Re: [RESOLVED] Implicit default ctor - what is it for?
Thanks laser.
Now it seems to be correctly resolved thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|