fork download
  1. #include <iostream>
  2.  
  3. class C
  4. {
  5. public:
  6. void f() { std::cout << "f()\n"; }
  7. void g() const { std::cout << "g()\n"; }
  8. typedef void (C::*fp)();
  9. };
  10.  
  11. int main() {
  12.  
  13. C::fp pointer = &C::f;
  14.  
  15. C c;
  16.  
  17. (c.*pointer)();
  18.  
  19. pointer = &C::g; // Не работает
  20.  
  21. (c.*pointer)();
  22.  
  23. return 0;
  24. }
Compilation error #stdin compilation error #stdout 0s 2852KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:19:19: error: cannot convert ‘void (C::*)()const’ to ‘C::fp {aka void (C::*)()}’ in assignment
stdout
Standard output is empty