fork(1) download
  1. #include <functional>
  2. #include <iostream>
  3. #include <memory>
  4.  
  5. struct foo
  6. {
  7. int get_val() const
  8. {
  9. return 42;
  10. }
  11. };
  12.  
  13. int main()
  14. {
  15. foo obj;
  16. std::shared_ptr<foo> ptr = std::make_shared<foo>();
  17.  
  18. const auto getter = std::mem_fn( &foo::get_val );
  19.  
  20. std::cout << getter( obj ) << std::endl;
  21. std::cout << getter( ptr ) << std::endl;
  22. }
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
42
42