fork download
  1. #include <iostream>
  2. #include <memory>
  3. using namespace std;
  4. class Foo : public enable_shared_from_this<Foo>
  5. {
  6. public:
  7. void Test()
  8. {
  9. auto sp = shared_from_this();
  10. cout << sp.use_count() <<endl;
  11. }
  12. };
  13.  
  14. int main()
  15. {
  16. Foo f;
  17. f.Test();
  18. return 0;
  19. }
Runtime error #stdin #stdout #stderr 0s 4360KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
terminate called after throwing an instance of 'std::bad_weak_ptr'
  what():  bad_weak_ptr