On Jul 28, 5:41*pm, puzzlecracker <ironsel2...@gm ail.comwrote:
When would you use which?
#include <iostream>
#include <boost/shared_ptr.hpp>
#include <boost/weak_ptr.hpp>
using boost::shared_p tr;
using std::cin;
using std::cout;
class a{
public:
boost::weak_ptr <aclass_membe r;
};
int main() {
shared_ptr<amai nvar(new a);
cout<<mainvar.u se_count();
mainvar->class_member = mainvar;
cout<<mainvar.u se_count();
cout<<mainvar->class_member.u se_count();
int a;
cin>>a;
}
in the above code weak_ptr is the must. Even when mainvar pointer goes
out of scope the reference count is still 1 since it is pointed by
class_member(sh ared_ptr)
to avoid this use class_member(we ak_ptr) which in first does not
increase the reference count.