Say I have a vector of pointers to “Order” objects. Now I want to remove an order from this vector. I wonder if the following is the right way to remove such a pointer?
std::vector<Order*> orders;
// somehow I obtained a vector of Order*, and an iterator it that points to
// an order that I want to remove completely.
// does the following work?
Order *order = *it;
orders.erase(it);
delete order;
Was the pointer the result of
new? Has anyone else deleted it first? If “yes” and “no”, then your code will delete the object.