fork download
  1. #include <iostream>
  2. #include <map>
  3.  
  4. struct O
  5. {
  6. std::map<size_t,double(*)()> m;
  7. double operator[](size_t index)
  8. {
  9. return m[index]();
  10. }
  11. };
  12.  
  13. double mydouble = 1.25;
  14.  
  15. double myFunction()
  16. {
  17. return mydouble;
  18. }
  19.  
  20. int main()
  21. {
  22. O myArray;
  23. myArray.m[2] = &myFunction;
  24. std::cout << myArray[2] << std::endl;
  25. return 0;
  26. }
  27.  
Success #stdin #stdout 0s 3032KB
stdin
Standard input is empty
stdout
1.25