fork download
  1. #include <iostream>
  2. #include <memory>
  3.  
  4. using namespace std;
  5.  
  6. struct mirror_ptr
  7. {
  8. int*& ptr;
  9. mirror_ptr(int*& p) : ptr(p){}
  10. };
  11.  
  12.  
  13. int main() {
  14. int* raw_ptr = new int;
  15. shared_ptr<mirror_ptr> shared = make_shared<mirror_ptr>(raw_ptr);
  16.  
  17. delete raw_ptr;
  18. raw_ptr = nullptr;
  19.  
  20. //...
  21.  
  22. if (shared->ptr) { std::cout << "ok\n"; }
  23. std::cout << "end\n";
  24. // your code goes here
  25. return 0;
  26. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
end