By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,820 Members | 1,187 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,820 IT Pros & Developers. It's quick & easy.

std::vector reserve / constructor question

P: n/a
When I create a vector with:

vector<doublev(10);

am I right to assume that it has initialized ten elements with the
number zero?

What if I want to just make space for 10 elements I'll add in later? Is
the best way to do that:

vector<doublev;
v.reserve(10);

That is to say, there is no constructor that reserves space without
entering values (default or otherwise), right?
Mar 22 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Mar 22, 1:20 pm, Chris Roth <czr...@mail.usask.cawrote:
When I create a vector with:

vector<doublev(10);

am I right to assume that it has initialized ten elements with the
number zero?

What if I want to just make space for 10 elements I'll add in later? Is
the best way to do that:

vector<doublev;
v.reserve(10);

That is to say, there is no constructor that reserves space without
entering values (default or otherwise), right?
Right, unfortunately.

Cheers! --M

Mar 22 '07 #2

P: n/a
Chris Roth wrote:
When I create a vector with:

vector<doublev(10);

am I right to assume that it has initialized ten elements with the
number zero?
Yes. The technical term here is that the elements are
"value-initialized" which, for built-in types, is the same as
zero-initialized.
>
What if I want to just make space for 10 elements I'll add in later? Is
the best way to do that:

vector<doublev;
v.reserve(10);
That works fine.
>
That is to say, there is no constructor that reserves space without
entering values (default or otherwise), right?
Yes.

Mar 22 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.