fork(5) download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class Test
  6. {
  7. public:
  8. void foo()
  9. {
  10. cout << "Test::foo called" << endl;
  11. }
  12. };
  13.  
  14. class Tester: public Test
  15. {
  16. public:
  17. void boo()
  18. {
  19. cout << "Tester::boo called" << endl;
  20. }
  21. };
  22.  
  23. int main()
  24. {
  25. //объявляем тип указателя:
  26. typedef void (Test::* pToFunc)();
  27.  
  28. //создаём объект этого типа и инициализируем его:
  29. pToFunc pt = &Tester::boo;
  30.  
  31. // Можно и по указателю:
  32. Test *test = new Test;
  33. Tester *tester = new Tester;
  34.  
  35. (test->*pt)();
  36.  
  37. delete test;
  38. delete tester;
  39. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:29:28: error: cannot convert ‘void (Tester::*)()’ to ‘pToFunc {aka void (Test::*)()}’ in initialization
stdout
Standard output is empty