Hi everyone
I made a vector of pointers and the problem is that I have trouble deleting the pointers in the vector. I used to simply do vector.clear() or vector.erase() however it does not clear the actual memory. And I tried something like this:
1 2 3 4
std::vector<Foo*> Vector;
std::vector<Foo*>::iterator i;
for (i = Vector.begin(); i < Vector.end(); i++)
delete *i;
Adding on to what @LB said, if you ever find yourself copying the vector you should use std::shared_ptr instead. In general, it behaves just like a normal pointer, but if you want more detail look up std::shared_ptr and std::unique_ptr on the reference here.
@NT3 I would hope that when you copy a vector you don't expect that changing the elements in one changes the elements in the other too. That's not quite what a copy is.