fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class WVObject
  5. {
  6. protected:
  7. typedef bool (*EvalFun)(unsigned long);
  8.  
  9. bool evalA (unsigned long id) const { return true; }
  10. bool evalB (unsigned long id) const { return false; }
  11.  
  12. bool test (EvalFun fnctToEval) const
  13. {
  14. //hier der Zugriff auf die übergebene Methode
  15. bool res = (*fnctToEval) (4);
  16. return res;
  17. }
  18.  
  19. public:
  20. virtual void parse() = 0;
  21. };
  22.  
  23. //WVKnoten.hpp
  24. class WVKnoten : public WVObject
  25. {
  26. public:
  27. void parse () { cout << test(&WVObject::evalA); }
  28. };
  29.  
  30. int main() {
  31. WVKnoten obj;
  32. obj.parse();
  33. return 0;
  34. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In member function ‘virtual void WVKnoten::parse()’:
prog.cpp:9:10: error: ‘bool WVObject::evalA(long unsigned int) const’ is protected
     bool evalA (unsigned long id) const { return true; }
          ^
prog.cpp:27:42: error: within this context
  void parse () { cout << test(&WVObject::evalA); }
                                          ^
prog.cpp:27:47: error: no matching function for call to ‘WVKnoten::test(bool (WVObject::*)(long unsigned int)const)’
  void parse () { cout << test(&WVObject::evalA); }
                                               ^
prog.cpp:27:47: note: candidate is:
prog.cpp:12:10: note: bool WVObject::test(WVObject::EvalFun) const
     bool test (EvalFun fnctToEval) const
          ^
prog.cpp:12:10: note:   no known conversion for argument 1 from ‘bool (WVObject::*)(long unsigned int)const’ to ‘WVObject::EvalFun {aka bool (*)(long unsigned int)}’
stdout
Standard output is empty