auto spw = std::make_shared<Widget>(); // the pointed-to Widget’s ref count (RC) is 1. std::weak_ptr<Widget> wpw(spw); // wpw points to same Widget as spw. RC remains 1 ... spw = nullptr; // RC goes to 0, and the Widget is destroyed. // wpw now dangles ____________________________________
if (wpw.expired()) // if wpw doesn’t point to an objectâĂę