fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Container;
  5.  
  6. class F
  7. {
  8. public:
  9. typedef void (Container::*FuncPtr)();
  10.  
  11. F(Container &c, FuncPtr fp) : m_c(c), m_fp(fp) {}
  12. void Execute() { (m_c.*m_fp)(); }
  13. private:
  14. Container& m_c;
  15. FuncPtr m_fp;
  16. };
  17.  
  18. class Container
  19. {
  20. public:
  21. Container() : fps(*this, &Container::Func) { }
  22. void Func() { cout << "hello from Container::Func()" << endl; }
  23. void Execute() { fps.Execute(); }
  24. private:
  25. F fps;
  26. };
  27.  
  28. int main() {
  29. Container c;
  30. c.Execute();
  31. return 0;
  32. }
Success #stdin #stdout 0.01s 5516KB
stdin
Standard input is empty
stdout
hello from Container::Func()