I have a vector of shared_ptrs as below.
std::vector<std::shared_ptr<SharedThing>> things;
Now let's say I push a number of shared_ptrs onto the vector and each element now has a reference count of 1.
When I need to replace one of those elements with a new shared_ptr I want the old shared_ptr to go out of scope. Will regular element assignment achieve this or will it just copy the shared_ptr contents. For example:
things.at(0) = new_shared_ptr;
Will this decrement the reference count of things.at(0) and increment the count of new_shared_ptr?
Aucun commentaire:
Enregistrer un commentaire