fork download
  1. #include <iostream>
  2. #include <functional>
  3. using namespace std;
  4.  
  5. void dynamic_dispatch(const function<int()> &callback) {
  6. cout << "dynamic_dispatch: " << callback() << endl;
  7. }
  8.  
  9. int main() {
  10. int x = 1;
  11. int y = 2;
  12.  
  13. auto closure = [&] { return x + y; };
  14.  
  15. dynamic_dispatch(closure);
  16.  
  17. return 0;
  18. }
Success #stdin #stdout 0s 3272KB
stdin
Standard input is empty
stdout
dynamic_dispatch: 3