fork download
  1. #include <vector>
  2. #include <string>
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. struct S
  8. {
  9. vector<int> v;
  10. string s;
  11. string s2;
  12. int i;
  13. char c;
  14. };
  15.  
  16. void print_all(const S* arr, size_t n, const string S::*member)
  17. {
  18. while (n > 0)
  19. {
  20. cout << arr->*member << "\n";
  21. ++arr;
  22. --n;
  23. }
  24. }
  25.  
  26. int main(int, char**)
  27. {
  28. S my_array[3];
  29.  
  30. my_array[0].s = "a";
  31. my_array[1].s = "b";
  32. my_array[2].s = "c";
  33.  
  34. my_array[0].s2 = "d";
  35. my_array[1].s2 = "e";
  36. my_array[2].s2 = "f";
  37.  
  38. print_all(my_array, 3, &S::s);
  39. print_all(my_array, 3, &S::s2);
  40.  
  41. return 0;
  42. }
Success #stdin #stdout 0.01s 5388KB
stdin
Standard input is empty
stdout
a
b
c
d
e
f