I'm going crazy here, I'd really appreciate some help. I have the following piece of code:
Code:
vector<Type*> a_vector;
for (int i=0; i<n; i++) {
Type* ptr = new Type(this);
a_vector.push_back(ptr);
printf("i: %d, ptr: %p\n", i, ptr);
}
printf("size: %d, a_vector[0]: %p\n", a_vector.size(), a_vector[0]);
And I get this result:
Code:
i: 0, ptr: 0x80c8530
i: 1, ptr: 0x80c8648
i: 2, ptr: 0x80c8738
i: 3, ptr: 0x80c8828
size: 4, a_vector[0]: (nil)
I don't get it: I print ptr before doing push_back and it isn't nil, the final size of a_vector is 4, which shows it has indeed inserted all the pointers, but then the first one (and the others too, actually) is nil. How is this possible? Thanks a lot.