After reading this answer, it looks like it is a best practice to use smart pointers as much as possible, and to reduce the usage of “normal”/raw pointers to minimum.
Is that true?
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.
No, it’s not true. If a function needs a pointer and has nothing to do with ownership, then I strongly believe that a regular pointer should be passed for the following reasons:
shared_ptr, then you won’t be able to pass, say,scoped_ptrThe rule would be this – if you know that an entity must take a certain kind of ownership of the object, always use smart pointers – the one that gives you the kind of ownership you need. If there is no notion of ownership, never use smart pointers.
Example1:
Example2: