Jan 23
I recently wrote a piece of code that looked something like the following:
-
static const int NUM_TOTAL_VALUES = …;
-
typedef … T;
-
-
// Create vec and reserve NUM_TOTAL_VALUES spaces for later insertion
-
std::vector<T> vec(NUM_TOTAL_VALUES);
-
-
// Insert values into vec
-
for (int i = 0; i != NUM_TOTAL_VALUES; ++i)
-
vec.push_back(…);
-
-
// vec should now have NUM_TOTAL_VALUES values in it (but doesn’t!)
What’s wrong with this code?
Recent Comments