fork download
  1. #include <iostream>
  2. #include <memory>
  3. using namespace std;
  4.  
  5. class T;
  6.  
  7. std::weak_ptr<T> wptr;
  8.  
  9. class T
  10. {
  11. public:
  12. T() { }
  13. ~T() {
  14. std::cout << "in dtor" << std::endl;
  15. std::cout << (wptr.expired() ? "expired" : "not expired") << std::endl;
  16. }
  17. };
  18.  
  19. int main() {
  20. {
  21. auto ptr = std::make_shared<T>();
  22. wptr = ptr;
  23. std::cout << (wptr.expired() ? "expired" : "not expired") << std::endl;
  24. }
  25. return 0;
  26. }
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
not expired
in dtor
expired