fork download
  1. #include <iostream>
  2. #include <functional>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. class foo
  8. {
  9. public:
  10. void setEmail(string s) { cout << "setEmail: " << s << endl; }
  11. void setPassword(string s) { cout << "setPassword: " << s << endl; }
  12. void setName(string s) { cout << "setName:" << s << endl; }
  13. void setAddress(string s) { cout << "setAddress:" << s << endl; }
  14. void setPhone(string s) { cout << "setPhone:" << s << endl; }
  15. };
  16.  
  17. typedef std::function<void (string)> fptr;
  18.  
  19. int main()
  20. {
  21. foo *newAC = new foo;
  22.  
  23. std::function<void (string)> functions[5] = {
  24. bind(&foo::setEmail, newAC, placeholders::_1),
  25. bind(&foo::setPassword, newAC, placeholders::_1),
  26. bind(&foo::setName, newAC, placeholders::_1),
  27. bind(&foo::setAddress, newAC, placeholders::_1),
  28. bind(&foo::setPhone, newAC, placeholders::_1),
  29. };
  30.  
  31. for (int i = 0; i < 5; i++)
  32. functions[i]("YA");
  33.  
  34. return 0;
  35. }
Success #stdin #stdout 0s 3416KB
stdin
Standard input is empty
stdout
setEmail: YA
setPassword: YA
setName:YA
setAddress:YA
setPhone:YA