fork download
  1. auto addition = [] (double a, double b) { return a + b; };
  2.  
  3. auto substruction = [] (double a, double b) { return a - b; };
  4.  
  5. auto divide = [] (double a, double b) { return a / b; };
  6.  
  7. auto multiplie = [] (double a, double b) { return a * b; };
  8.  
  9. typedef std::function<double (double, double)> DoubleFunc;
  10.  
  11. int main()
  12. {
  13. std::vector<DoubleFunc> funcVector;
  14.  
  15. funcVector.push_back(addition);
  16. funcVector.push_back(substruction);
  17. funcVector.push_back(multiplie);
  18. funcVector.push_back(divide);
  19.  
  20. std::for_each(funcVector.begin(), funcVector.end(), []
  21. (DoubleFunc func)
  22. {
  23. std::cout << func(3.14159, 100500) << std::endl;
  24. });
  25.  
  26. system("pause");
  27. return 0;
  28. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:9:9: error: 'function' in namespace 'std' does not name a type
prog.cpp: In function 'int main()':
prog.cpp:13:5: error: 'vector' is not a member of 'std'
prog.cpp:13:17: error: 'DoubleFunc' was not declared in this scope
prog.cpp:13:29: error: 'funcVector' was not declared in this scope
prog.cpp:20:5: error: 'for_each' is not a member of 'std'
prog.cpp:21:6: error: 'DoubleFunc' is not a type
prog.cpp: In lambda function:
prog.cpp:23:9: error: 'cout' is not a member of 'std'
prog.cpp:23:42: error: 'func' cannot be used as a function
prog.cpp:23:47: error: 'endl' is not a member of 'std'
prog.cpp: In function 'int main()':
prog.cpp:26:19: error: 'system' was not declared in this scope
stdout
Standard output is empty