It's my understanding that a call to vector::reserve typically forces a reallocation, and invalidates all iterators, pointers, and references to objects contained in the vector. However, in this case I'm concerned about the validity of the pointer TO the vector. If a reallocation occurs, does the address of the vector itself change, and invalidate the pointer? If it does, what happens if I later use the indirection operator to call other vector methods, and how can that be avoided?
1 2 3 4 5 6 7
int bin_size = 50000;
vector<int> * temp;
for(int i = 0; i < a_num; ++i){
temp = new vector<int>();
temp->reserve(bin_size);
_ptrs_to_bins.push_back(temp);
}