What is the proper way to remove elements from a vector of object pointers without deleting the object it points to?
I am trying to selectively remove elements from my vector
bool CheckClosedNode(Node *tocheck)
return false; //Don't remove. Node is still open.
//std::cout << "node " << tocheck->id << " is being removed from open list..." << std::endl;
return true; // Remove. Node is closed.
It actually won't delete the nodes if they are pointers. When you allocate memory for an object using new it is your job to delete the pointer. Now if you had declared it like
vector<Node> this would be an issue since erase would have to call the deconstructor on Node. However a pointer is really like an int type (since it is just a memory address). When you remove it from a vector nothing happens to the memory it points to.