/* CSE 333 Su12 lecture 13 demo: usingweak.cc */ /* Gribble/Perkins */ // Simple example showing use of weak references to // allow circular structures to be reclaimed. #include #include #include using boost::shared_ptr; using boost::weak_ptr; int main(int argc, char **argv) { weak_ptr w; { shared_ptr x; { shared_ptr y(new int(10)); w = y; x = w.lock(); std::cout << *x << std::endl; } std::cout << *x << std::endl; } shared_ptr a = w.lock(); std::cout << a << std::endl; return 0; }