fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct foo
  5. {
  6. int a, b;
  7. };
  8.  
  9. foo arr[3] = {foo{0, 1}, foo{0, 1}, foo{0, 1}};
  10.  
  11. void func(int foo::*member)
  12. {
  13. for (auto el : arr)
  14. cout << el.*member << ' ';
  15. }
  16.  
  17. int main() {
  18. func(&foo::a);
  19. cout << '\n';
  20. func(&foo::b);
  21. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
0 0 0 
1 1 1