I know, that std::shared_ptr
uses reference counting, so it has copy&move semantics, on the other hand std::unique_ptr
(hence the name unique) only has move semantics, so trying to copy it is a compile error.
However, its not quite clear for me how big of a deal is that. Can I simply use std::shared_ptr
over std::unique_ptr
in most cases, or should I use std::unique_ptr
whenever possible, as it's far more efficient because it doesn't have to take care of reference counting?
Also, I know that smart pointers are useful when dealing with, for example exception safety, but are they a mean to generally replace traditional T*
pointers? Is it a good programming practice to use smart pointers over traditional T*
pointers whenever possible?
Aucun commentaire:
Enregistrer un commentaire