very simple shared_ptr and copy constructor question
So, I've been using std::auto_ptr for some time, and have always been careful to either create a copy constructor or make it private (same for assignment). But now that I am becoming a boost::shared_ptr convert, I think that is no longer necessary. Is that so? Thanks, Robert
Hi Robert, As far as I know, shared_ptr is the equivalent of auto_ptr, but with no guarantees about who copies it: ie. you can copy the object with no worries about memory leaks. In other words, yes.
Robert Marion wrote:
So, I've been using std::auto_ptr for some time, and have always been careful to either create a copy constructor or make it private (same for assignment). But now that I am becoming a boost::shared_ptr convert, I think that is no longer necessary. Is that so?
It's not necessary if the generated copy constructor has the semantics that you want. Keep in mind that all copies of shared_ptr refer to the same pointee. So it depends on the context. If you aren't sure, disabling the copy constructor is still a good guideline to apply by default.
participants (3)
-
Darren Garvey
-
Peter Dimov
-
Robert Marion