CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jan 2012
    Location
    USA
    Posts
    91

    [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.

  2. #2
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    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.

  3. #3
    Join Date
    Jan 2012
    Location
    USA
    Posts
    91

    Re: Implicit default ctor - what is it for?

    I see, thank you.

  4. #4
    Join Date
    Jul 2007
    Posts
    249

    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)

  5. #5
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    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.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  6. #6
    Join Date
    Jul 2007
    Posts
    249

    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
  •  





Click Here to Expand Forum to Full Width

Featured