I have an array of pointers to vectors vector<int> *F[12];
and I wish to initialize some vectors and store their addresses in F.
for(uint i = A; i <= B; ++i){
vector<uint> newvec(pow2(i), 0);
F[i] = &newvec;
}
But when I try to access them later, I find that they are not all zero:
for(uint i = A; i <= B; ++i){
for(uint j = 0; j <= pow2(i); ++j){
if((*F[i]).at(j) != 0){
cout << i << "/" << j << "/" << (*F[i]).at(j) << "|";
}
}
}
I assume this has something to do with the scope of the declared vector. Why has the memory been freed? Do I have to use malloc
and create a vector from that?