Page 92, C++ primer 4th edition

Discussion in 'C++' started by asdf, Nov 21, 2006.

  1. asdf

    asdf Guest

    How to understand the last paragraph? Who'd like to give me an example?

    There is a third possibility: The element type might be of a class type
    that does not define any constructors. In this case, the library still
    creates a value-initialized object. It does so by value-initializing
    each member of that object.
    asdf, Nov 21, 2006
    #1
    1. Advertising

  2. asdf wrote:
    > How to understand the last paragraph? Who'd like to give me an
    > example?
    >
    > There is a third possibility: The element type might be of a class
    > type that does not define any constructors. In this case, the library
    > still creates a value-initialized object. It does so by
    > value-initializing each member of that object.


    Is this the paragraph you want to understand?

    'Element', eh? Probably talking about arrays. Class that does not
    define "any" constructors means that it has an implicitly-declared
    and implicitly-defined (hopefully) default constructor (c-tor that
    doesn't take any arguments). If it's defined (IOW, if all members
    to be initialised *can* be initialised using default-initialisation),
    then initialisation of an array [of objects] of such class will make
    all elements of the array default-initialised.

    class A { int a; public: A() : a() {} };
    class B { A a; };

    int main() {
    B *pb = new B[10](); // ten elements, all value-initialised
    }

    In the example above, each 'a' of each 'B' will have it's 'a' set
    to 0 (value-initialisation).

    If this is not what the book is talking about, then you have to
    explain what you're asking about, by quoting a bit more of the book.
    I don't have a copy.

    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
    Victor Bazarov, Nov 21, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andrew Koenig

    Announcement: C++ Primer, 4th edition

    Andrew Koenig, Jan 17, 2005, in forum: C++
    Replies:
    9
    Views:
    426
    red floyd
    Jan 19, 2005
  2. hajime

    C++ Primer, 4th Edition

    hajime, Aug 16, 2005, in forum: C++
    Replies:
    5
    Views:
    441
    hajime
    Aug 16, 2005
  3. asdf
    Replies:
    6
    Views:
    274
    Default User
    Sep 18, 2006
  4. asdf
    Replies:
    3
    Views:
    242
    KiLVaiDeN
    Oct 11, 2006
  5. arnuld
    Replies:
    17
    Views:
    575
    Marcus Kwok
    Oct 17, 2006
Loading...

Share This Page