fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <unordered_map>
  4.  
  5. struct A {
  6. int first;
  7. int second;
  8. };
  9.  
  10. using member_ptr = int A::*;
  11.  
  12. using member_map = std::unordered_map<std::string, member_ptr>;
  13.  
  14. static member_map Amap = {
  15. {"first", &A::first},
  16. {"second", &A::second}
  17. };
  18.  
  19. int main()
  20. {
  21. A a;
  22. a.*(Amap["first" ]) = 42;
  23. a.*(Amap["second"]) = 24;
  24. std::cout << a.first << std::endl
  25. << a.second << std::endl;
  26. return 0;
  27. }
  28.  
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
42
24