lundi 3 juin 2019

Smart pointer constructor: what is the difference between passing 'new' and std::make_...? [duplicate]

This question already has an answer here:

I would like to know the difference between these two declarations:

  • std::unique_ptr<Foo> pFoo(new Foo());
  • std::unique_ptr<Foo> pFoo = std::make_unique<Foo>();

I heard that the second usage is for exception safety, therefore preferred one? Is that also correct?

Aucun commentaire:

Enregistrer un commentaire