I love this book, sadly it does not cover smart pointers as they were not part of the standard back then. So when reading the book can I fairly substitute every mentioned pointer by a smart pointer, respectively reference?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Well, there are different kinds of smart pointers. For example:
You could create a
scoped_ptrclass, which would be useful when you’re allocating for a task within a block of code, and you want the resource to be freed automatically when it runs of of scope.Something like:
Additionally you could create a
shared_ptrwho acts the same but keeps a ref count. Once the ref count reach 0 you deallocate.shared_ptrwould be useful for pointers stored in STL containers and the like.So yes, you could use smart pointers for most of the purposes of your program.
But think judiciously about what kind of smart pointer you need and why.
Do not simply “find and replace” all the pointers you come across.