#include // for EXIT_SUCCESS #include // for std::cout, std::endl #include // for std::shared_ptr, std::weak_ptr using std::shared_ptr; using std::weak_ptr; using std::cout; using std::endl; int main(int argc, char **argv) { weak_ptr w; // temporary inner scope (!) { shared_ptr x; // an inner temporary inner scope (!!) { shared_ptr y(new int(10)); w = y; x = w.lock(); cout << *x << endl; } cout << *x << endl; } shared_ptr a = w.lock(); cout << a << endl; return EXIT_SUCCESS; }