#include <boost/shared_ptr.hpp> #include <boost/weak_ptr.hpp> #include <iostream> using boost::shared_ptr; using boost::weak_ptr; int main(int argc, char **argv) { weak_ptr<int> w; { shared_ptr<int> x; { shared_ptr<int> y(new int(10)); w = y; x = w.lock(); std::cout << *x << std::endl; } std::cout << *x << std::endl; } shared_ptr<int> a = w.lock(); std::cout << a << std::endl; return 0; }