fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class B {
  5. public:
  6. void up() {
  7. std::cout << "up" << std::endl;
  8. }
  9. void down() {
  10. std::cout << "down" << std::endl;
  11. }
  12. void init( void(B::*someFunc)() , void(B::*otherFunc)() ) {
  13. m_execute = someFunc;
  14. B* newB = new B();
  15. m_b = newB;
  16. m_b->m_execute = otherFunc;
  17. }
  18. void find() {
  19. run_my_execute();
  20. m_b->run_my_execute();
  21. }
  22. private:
  23. void(B::*m_execute)();
  24. B* m_b;
  25. void run_my_execute() {
  26. (this->*m_execute)();
  27. }
  28. };
  29.  
  30. int main(){
  31. B* b = new B();
  32. b->init(&B::up, &B::down);
  33. b->find();
  34. return 0;
  35. }
  36.  
  37.  
Success #stdin #stdout 0s 4284KB
stdin
Standard input is empty
stdout
up
down