Simply, in some part of code, I create an object and assign to unique_ptr
:
unique_ptr<Node> n ( CreateNode() );
container.place(id, std::move(n));
The definition of place
is:
void place(int id, unique_ptr<Node> n)
{
mappings_[id] = std::move(n); // std::map<int, unique_ptr<Node>> mappings_;
}
I'm currently trying to hunt a bug where the alleged object that was retrieved from the map has some internal pointers completely twisted, which might have been a consequence of that the object was really deleted, but this fact was somewhat missed. Questions:
- Should this
n
be ofunique_ptr<Node>
type orunique_ptr<Node>&&
? - What are the consequences of both of the above?
Aucun commentaire:
Enregistrer un commentaire