fork download
  1. #include <cmath>
  2. #include <functional>
  3. #include <map>
  4. #include <string>
  5. #include <iostream>
  6.  
  7. typedef double(*mathFunc)(double);
  8.  
  9. int main() {
  10. std::map< std::string, mathFunc > funcMap;
  11.  
  12. funcMap[std::string( "sqrt")]= std::sqrt;
  13.  
  14. double sqrt2 = (funcMap.at("sqrt"))(2.0);
  15.  
  16. std::cout << "Result: "<< sqrt2 << std::endl;
  17. return 0;
  18. }
Success #stdin #stdout 0s 3032KB
stdin
Standard input is empty
stdout
Result: 1.41421