fork(2) download
  1. #include <functional>
  2. #include <memory>
  3. #include <iostream>
  4.  
  5. struct MyClass
  6. {
  7. int x;
  8. MyClass(int x_) : x(x_) { }
  9. void some_func()
  10. {
  11. std::cout << x << std::endl;
  12. }
  13. };
  14.  
  15. int main(int argc, char *argv[])
  16. {
  17. std::shared_ptr<MyClass> pmc;
  18. auto mfp = std::bind(&MyClass::some_func, std::ref(pmc));
  19.  
  20. pmc = std::make_shared<MyClass>(42);
  21. mfp();
  22.  
  23. pmc = std::make_shared<MyClass>(1729);
  24. mfp();
  25. }
  26.  
Success #stdin #stdout 0s 3032KB
stdin
Standard input is empty
stdout
42
1729