fork download
  1. #include <iostream>
  2. #include <functional>
  3.  
  4. struct my_f_params {
  5. double flag;
  6. std::function<double(double)> inter_auto;
  7. };
  8.  
  9. double xrootf(double x, void * p)
  10. {
  11. my_f_params * params = static_cast<my_f_params*>(p);
  12. return params->flag * params->inter_auto(x);
  13. }
  14.  
  15. auto new_f(double x){
  16. return [x](double y) {
  17. return x * y;
  18. };
  19. }
  20.  
  21. int main(int argc, char const *argv[])
  22. {
  23. my_f_params p;
  24. p.flag = 123.45;
  25. p.inter_auto = new_f(-0.5);
  26. std::cout << xrootf(+2, &p) << std::endl;
  27. return 0;
  28. }
Success #stdin #stdout 0s 4632KB
stdin
Standard input is empty
stdout
-123.45