????7??boost::weak_ptr
????boost::weak_ptr ???? boost ???????? namespace boost ?У????????? #include<boost/smart_ptr.hpp> ???????á?
??????? boost::weak_ptr ???????????????????潲??????????? boost::scoped_ptr??boost::shared_ptr ?????????????????????е???????????????????????????? boost::weak_ptr????????Щ?????????????????
????????С????? boost::weak_ptr ?????? boost::shared_ptr ???????????????????????????????????????????????ü?????boost::weak_ptr ?? boost::shared_ptr ???????Observer?????????????ζ?? boost::weak_ptr ??? boost::shared_ptr ?????????????????????ü????????????? boost::shared_ptr ?Ч??????? boost::weak_ptr ?????Ч??
??????????????????????
????void TestWeakPtr() {
????boost::weak_ptr<Simple> my_memory_weak;
????boost::shared_ptr<Simple> my_memory(new Simple(1));
????std::cout << "TestWeakPtr boost::shared_ptr UseCount: " << my_memory.use_count() << std::endl;
????my_memory_weak = my_memory;
????std::cout << "TestWeakPtr boost::shared_ptr UseCount: " << my_memory.use_count() << std::endl;
????}
??????н?????
????Simple: 1
????TestWeakPtr boost::shared_ptr UseCount: 1
????TestWeakPtr boost::shared_ptr UseCount: 1
????~Simple: 1
????????????????????????????????ü???????????仯?????????????????????????????????????
???????????????????boost::weak_ptr ????????????????????????????????????????κ????????? boost::weak_ptr ?????????????????У?????????????????????????????????????????????????ж?????? boost::weak_ptr?????????????? boost::shared_ptr????????????????????? boost::weak_ptr ???????????????????????????????????????? boost::shared_ptr ?????ü????????????????????????????
????8??boost::intrusive_ptr
????boost::intrusive_ptr???? boost ???????? namespace boost ?У????????? #include<boost/smart_ptr.hpp> ???????á?
???????????? 6 ??????????????????????? C++ ???????????????????ж?????? boost::intrusive_ptr??????????????????????????????????ü???????????????????????ü?????????????????????b??????????о????????????????????????????ù??????????????????о??????????J??
???????????
????????????????????????б??????Щ??????????????
????1?????????? boost ???????£??????? std::auto_ptr??????????????? C++ ??????????????????[2]??
????2??????????????蹲???????£???? boost::scoped_ptr??????????????? boost::scoped_array????
????3???????????????????£???? boost::shared_ptr??????????????? boost::shared_array????
????4??????????? boost::shared_ptr ??????????????????ü?????????£???? boost::weak_ptr???????????????????С?
????5????????????????????????????У???????? delete ???????? C ????? free ??????????????????????????????