Group: comp.lang.c++
From: Jerry Coffin
Date: Sunday, April 13, 2008 11:39 AM
Subject: Re: Initialization of vectors in c++

In article <03277800-7557-456d-96b8-
d4d164b4eb0b@s39g2000prd.googlegroups.com>, pauldepstein@att.net says...
> Experimenting at home with visual c++, I see that int main()
> {std::vector vect(5);} creates a vector whose 5 initial
> values are all 0. Is this standard or might the five initial values
> be different from 0? I'm a bit surprised by this as I would expect
> vect to consist of five uninitialized doubles. Why is it that double
> x; introduces a double which is uninitialized and yet the above vect
> is initialized? Or is this just a matter of the definition of the c++
> language which should just be accepted, and can't be derived from some
> other principle?

As others have pointed out, the value is guaranteed to be zero.

What they haven't pointed out (directly) is that you can specify another
value if you prefer. E.g.:

std::vector vect(5, 15.0);

--
Later,
Jerry.

The universe is a figment of its own imagination.

Safety Articles | Usenet Groups | Usenet News | Bluegrass