I’m using a vector to hold pointers to a class.
class fooContainer{
private:
vector <Foo *> foos;
public:
void processFoo(int fooIndex);
};
The problem I face is that pop_back() drops the element, I only want to remove it from the vector but not touch the object in question. I also need to remove all elements from a vector in preparation for restarting the main cycle (but keeping the same vector, which is a class attribute).
I need a structure that has dynamic sizing but does not copy or delete its elements, being content to hold pointers to them.
Is there a better alternative structure, or am I using them all wrong?
Vector does copy and destroy its contents, but in your case the content is pointer to object and not the object.
The specific pointer to the object will be destroyed, but other pointers to that object, and the object itself, won’t be destroyed.