fork(3) download
  1. template <typename T, typename K, K (T::*F)() const = &T::get>
  2. struct Foo
  3. {
  4. K retrieve(const T & t) { return (t.*F)(); }
  5. };
  6.  
  7. struct X { int get() const { return 9; } };
  8.  
  9. #include <iostream>
  10.  
  11. int main()
  12. {
  13. X x;
  14. std::cout << Foo<X, int>().retrieve(x) << "\n";
  15. }
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
9