Let's say I have a vector of MyObject*
. I would like to pull out an item from the vector and get that item (i.e. not using erase
or pop_back
because it deletes the pointer).
So, in code, is there an easy way to to this ?
std::vector<MyObject *> items;
MyObject *takeAt(unsigned int index) {
// find item, then take it off from the list
return item;
}
I have ideas, like using std::transform
to generate a new vector without this particular item, and then set this new vector. But has anyone a better idea ?
Aucun commentaire:
Enregistrer un commentaire