fork(3) download
  1. #include <iostream>
  2.  
  3. class Hoge {
  4. private:
  5. void f() { std::cout << "hoge" << std::endl; }
  6. public:
  7. Hoge() {}
  8. };
  9.  
  10. int main() {
  11. // ordinary
  12. Hoge *hoge = new Hoge();
  13. hoge->f();
  14. // vir function-address
  15. void (Hoge::*private_f)() = &Hoge::f;
  16. (hoge->*private_f)();
  17. delete hoge;
  18. }
  19. /* end */
  20.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:5:8: error: ‘void Hoge::f()’ is private
   void f() { std::cout << "hoge" << std::endl; }
        ^
prog.cpp:13:13: error: within this context
     hoge->f();
             ^
prog.cpp:5:8: error: ‘void Hoge::f()’ is private
   void f() { std::cout << "hoge" << std::endl; }
        ^
prog.cpp:15:40: error: within this context
     void (Hoge::*private_f)() = &Hoge::f;
                                        ^
stdout
Standard output is empty