I'm a little bit confused with scoped_ptr. Can I still pass that
pointer by value into a function like I did with shared_ptr in the
above example? I just tried it and it doesn't compile. From what I
understand scoped_ptr is only used inside a function and shared_ptr is
for passing objects into functions without the developers who work on
the code worrying about reference counts, no? Please correct me if I'm
wrong.
Max
On Wed, Jul 28, 2010 at 11:50 AM, Patrick Loney
If I can pass the object by reference to a function, then is there a need to use shared pointers?
Not if you know the lifetime of your object and it won't be deleted before the function has finished. You may find scoped pointers useful though: http://www.boost.org/doc/libs/1_43_0/libs/smart_ptr/scoped_ptr.htm
I use shared_ptr like a "poor-man's" garbage collection. Instead of having
Ahh, being a c++ developer I see garbage collection as a poor man's raii (you can't even control when something is destructed for gods' sake ;))
Maybe I am using shared_ptr wrong but at least for my project it seems to work well.
Scoped_ptr offers the automatic memory management you discuss without the additional functionality of shared_ptr (i.e. shared_ptr is a scoped_ptr with added reference counting functionality) _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users