fork(1) download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. struct Foo {
  5. void setEmail(std::string) {
  6. std::cout << __func__ << ", this:" << this << std::endl;
  7. }
  8.  
  9. void setPassword(std::string) {
  10. std::cout << __func__ << ", this:" << this << std::endl;
  11. }
  12.  
  13. void setName(std::string) {
  14. std::cout << __func__ << ", this:" << this << std::endl;
  15. }
  16.  
  17. void setAddress(std::string) {
  18. std::cout << __func__ << ", this:" << this << std::endl;
  19. }
  20.  
  21. void setPhone(std::string) {
  22. std::cout << __func__ << ", this:" << this << std::endl;
  23. }
  24. };
  25.  
  26. int main() {
  27. void(Foo::*functions[])(std::string) = {
  28. &Foo::setEmail, &Foo::setPassword, &Foo::setName, &Foo::setAddress, &Foo::setPhone
  29. };
  30.  
  31. constexpr int n = sizeof(functions) / sizeof(functions[0]);
  32.  
  33. Foo foo;
  34. Foo *newAC = &foo;
  35. std::cout << "newAC:" << newAC << std::endl;
  36. for (int i = 0; i < n; ++i) {
  37. (newAC->*functions[i])("hi");
  38. }
  39. return 0;
  40. }
  41.  
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
newAC:0xbfae7e81
setEmail, this:0xbfae7e81
setPassword, this:0xbfae7e81
setName, this:0xbfae7e81
setAddress, this:0xbfae7e81
setPhone, this:0xbfae7e81