fork download
  1. #include <iostream>
  2. #include <functional>
  3. using namespace std;
  4.  
  5. void functionA(int a)
  6. {
  7. cout << "Thanks for calling me with " << a << endl;
  8. }
  9.  
  10. template <typename F>
  11. void encapsulateFunction(F f, int val)
  12. {
  13. std::function<void(int)> f_display = f;
  14.  
  15. // f_display now points to the function encapsulated
  16. f_display(val);
  17. }
  18.  
  19.  
  20.  
  21. int main() {
  22.  
  23. encapsulateFunction(functionA, 22);
  24.  
  25. return 0;
  26. }
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
Thanks for calling me with 22