Hello,
I have a (simple?) C++ question regarding the behaviour of resize in an stl vector.
Suppose I do the following:
On line 2, I reserve the space for 10 elements in the vector (capacity is 10, size is 0). The vector remains empty, but it can grow up to 10 elements without requiring internal reallocation. I then add 2 elements on lines 3 and 4.
The question is regarding the resize: obviously, this removes all the vectorelements (setting the size of the vector to 0), but is the capacity of the vector altered (is it still 10, or has it also been set to 0)?
(I can write a testprogram for it, but wondered if this behaviour has been defined, or is compiler dependant)
Thanks!
Jörg
I have a (simple?) C++ question regarding the behaviour of resize in an stl vector.
Suppose I do the following:
Code:
std::vector<int> myVector; // 1 myVector.reserve(10); // 2 myVector.push_back(1); // 3 myVector.push_back(2); // 4 myVector.resize(0,0); // 5
The question is regarding the resize: obviously, this removes all the vectorelements (setting the size of the vector to 0), but is the capacity of the vector altered (is it still 10, or has it also been set to 0)?
(I can write a testprogram for it, but wondered if this behaviour has been defined, or is compiler dependant)
Thanks!
Jörg
Comment