fork download
  1. #include <iostream>
  2. #include <memory>
  3.  
  4. class Hoge {
  5. private:
  6. int a;
  7. void f() { std::cout << "hoge:" << a << std::endl; }
  8. public:
  9. void (Hoge::*g1())() { return &Hoge::f; }
  10. int (Hoge::*g2()) { return &Hoge::a; }
  11. Hoge(int a) : a(a){}
  12. };
  13.  
  14. int main() {
  15. std::shared_ptr<Hoge> hoge = std::make_shared<Hoge>(12345);
  16. (hoge.get()->*(hoge->g1()))();
  17. hoge.get()->*(hoge->g2()) = 54321;
  18. (hoge.get()->*(hoge->g1()))();
  19. return 0;
  20. }
  21. /* end */
  22.  
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
hoge:12345
hoge:54321