fork download
  1. #include <iostream>
  2. #include <array>
  3. struct Foo {
  4. int one() { std::cout << "one\n"; return 1; }
  5. int two() { std::cout << "two\n"; return 2; }
  6. int three() { std::cout << "three\n"; return 3; }
  7. };
  8. std::array<int(Foo::*)(), 3> a = {{
  9. &Foo::one,
  10. &Foo::two,
  11. &Foo::three,
  12. }};
  13. int main() {
  14. Foo f;
  15. std::cout << "1: " << (f.*a[0])() << "\n";
  16. std::cout << "2: " << (f.*a[1])() << "\n";
  17. std::cout << "3: " << (f.*a[2])() << "\n";
  18. }
Success #stdin #stdout 0s 4452KB
stdin
Standard input is empty
stdout
one
1: 1
two
2: 2
three
3: 3