fork download
  1. #include <iostream>
  2.  
  3. class C {
  4. private:
  5. int a;
  6. void h() { std::cout << "C::a = " << this->a << std::endl; }
  7. public:
  8. C(int a) : a(a) {}
  9. void (C::*g())() { return &C::h; }
  10. };
  11.  
  12. int main() {
  13. C *obj = new C(12345);
  14.  
  15. void (C::*f)();
  16. f = obj->g();
  17. (obj->*(f))();
  18.  
  19. delete obj;
  20. return 0;
  21. }
  22.  
  23.  
Success #stdin #stdout 0s 4372KB
stdin
Standard input is empty
stdout
C::a = 12345