#include <iostream>
#include <memory>
using namespace std;
class Foo : public enable_shared_from_this<Foo>
{
  Foo() = default;
  /*should be virtual ?????*/
  ~Foo()
  {
    cout << "des" << endl;
  }
  

public:
  
  static shared_ptr<Foo> Create() {
    class PrivateFoo : public Foo { /*empty*/ };
    return std::make_shared<PrivateFoo>();
  }
  void Test()
  {
    auto sp = shared_from_this();
    cout << sp.use_count() <<endl;
  }
};

int main()
{
  auto f = Foo::Create();
  f->Test();
  
  return 0;
}
