I'm adding a child element to a parent element. The parent's addChildElement()
takes a raw pointer (and belongs to a library that I can't change), then assumes ownership and deletes.
std::unique_ptr<Element> child {new Element};
// ...do things...
parent.addChildElement (child.release()); // will be deleted by parent
Is this correct modern practice? To use a unique_ptr until the last possible moment, rather than a raw pointer?
Aucun commentaire:
Enregistrer un commentaire