std::vector<std::vector<int>> vecOfVecs;
vecOfVecs.resize(10);
What will be positions 0-9 of vecOfVecs? Instances of std::vector?
If so, is this legitimate:
std::vector<int> *pToVec = &(vecOfVecs[0]);
pToVec->push_back(10);
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The “canonical” definition of
std::vector::resizein C++03 actually has two parameters, not one, with the second argument being the element value that is used as a “fill value” for the freshly created elements. The second parameter has a default argument equal to a value-initialized object of element type. This means that your callis actually translated into a
call. I.e. it is actually you who implicitly supplied a default-constructed instance of
std::vector<int>to be used as an initializer for all new elements.Your
pToVec->push_back(10)call is perfectly legitimate.C++11 made some insignificant (in this context) changes to the definition of
resize, but the general effect remains the same: the new elements are value-initialized for you. They are ready to be used immediately after the call toresize.