-
February 11th, 2004, 03:27 PM
#1
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)
-
February 11th, 2004, 04:01 PM
#2
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
-
February 11th, 2004, 04:08 PM
#3
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|