fork download
  1. #include <iostream>
  2. #include <functional>
  3. using namespace std; // consider removing this line in serious projects
  4.  
  5. class T {
  6. public:
  7. double execute(function<double()> expression) {
  8. return expression();
  9. }
  10. };
  11.  
  12. int main() {
  13. T t;
  14. int a = 0, b = 1;
  15. function<double()> func = [&]() -> double {return 3 * a + 5 * b;};
  16. double result = t.execute([&]() -> double {return 3 * a + 5 * b;});
  17. cout << result << endl;
  18.  
  19. return 0;
  20. }
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
5