fork download
  1. #include <iostream>
  2.  
  3. class Foo{
  4. public:
  5. Foo(void* object): obj(object) {}
  6.  
  7. void callFunc(void (*func)(void *)){
  8. func(obj);
  9. }
  10.  
  11. private:
  12. void* obj;
  13. };
  14.  
  15. class Bar{
  16. public:
  17. Bar(): foo(this) {}
  18.  
  19. void callSomeFunc(){
  20. foo.callFunc(someFuncAdapter);
  21. }
  22.  
  23. void someFunc(){
  24. std::cout << "hi\n";
  25. }
  26.  
  27. static void someFuncAdapter(void *obj) {
  28. static_cast<Bar *>(obj)->someFunc();
  29. }
  30.  
  31. private:
  32. Foo foo;
  33. };
  34.  
  35. int main(){
  36. Bar bar;
  37. bar.callSomeFunc();
  38. return 0;
  39. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
hi