shared_ptr in boost library

hi
can some one tell me how shared_ptr works? i read this page but i can not understand... it doesnt have example in this page
http://www.cplusplus.com/reference/memory/shared_ptr/
is there anyone here? plzz help :(
Perhaps cppreference's explanation would work better? http://en.cppreference.com/w/cpp/memory/shared_ptr#Implementation_notes

(note that neither page describes shared_ptr in the boost library, both cplusplus.com and cppreference.com talk about C++. For boost, see http://www.boost.org/doc/libs/release/libs/smart_ptr/shared_ptr.htm )
Last edited on
shared_ptr has two members

1. the pointer to the object
2. the pointer to a reference counter


when the shared_ptr gets an non null object or another shared_ptr is assigned the reference count is increase by one
when the shared_ptr looses the object or is destroyed the reference count is decreased by one

if the reference count is 0 (no one uses the pointer to the object anymore) the object (if not null) is deleted.

this way you don't need to worry about the lifetime of the associated object
Topic archived. No new replies allowed.