CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2003
    Location
    Pasadena, CA
    Posts
    48

    question about initial values

    Ok, another question for the Standards weenies...

    I'm pretty sure I know the answer (A) but I'm gonna ask anyways.

    given...

    std::vector<int *> Vec(1);

    Vec is constructed using:
    vector(size_type n,
    value_type const & value = value_type(),
    allocator_type const & allocator = allocator_type());


    is the value of Vec[0] = ?
    (A) undefined
    (B) null/0

    This is more easily phrased as "what is the value of a default constructed pointer when constructor syntax is explicitly used?"
    The views expressed are those of the author and do not reflect any position taken by the Goverment of the United States of America, National Aeronautics and Space Administration (NASA), Jet Propulsion Laboratory (JPL), or California Institute of Technology (CalTech)

  2. #2
    Join Date
    Nov 2003
    Posts
    1,902
    B.

    From ISO/IEC FDIS 14882:1998(E) (Final Draft), section 8.5.7
    8.5 - Initializers [dcl.init]
    ...
    -5- ... To default-initialize an object of type T means:
    * if T is a non-POD class type (clause class), the default constructor for T is called (and the initialization is ill-formed if T has no accessible default constructor);
    * if T is an array type, each element is default-initialized;
    * otherwise, the storage for the object is zero-initialized.
    ...
    -7- An object whose initializer is an empty set of parentheses, i.e., (), shall be default-initialized.
    I woudn't count on your compiler being 100% standards conforming......we all know what assume spells

    gg

  3. #3
    Join Date
    Nov 2003
    Location
    Pasadena, CA
    Posts
    48
    Beautiful,

    This is exactly the type of succinct and definitive response I was looking for. Thanks for correcting my mistaken assumption!
    The views expressed are those of the author and do not reflect any position taken by the Goverment of the United States of America, National Aeronautics and Space Administration (NASA), Jet Propulsion Laboratory (JPL), or California Institute of Technology (CalTech)

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