fork download
  1. #include <iostream>
  2.  
  3. typedef int (*FuncPtr_t)(void*, int);
  4. static int simpleFunction(FuncPtr_t pfunc, void *context, int nos)
  5. {
  6. pfunc(context, nos);
  7. }
  8.  
  9. struct A {
  10. int i;
  11. int pf(int nos) { std::cout << i << " nos = " << nos << "\n"; return i; }
  12. };
  13.  
  14. int main() {
  15. A a { 1234 };
  16. // could combine the next two lines into one, I didn't.
  17. auto trampoline = [](void *inst, int nos) { return ((A*)inst)->pf(nos); };
  18. simpleFunction(trampoline, &a, 42);
  19. }
  20.  
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
1234 nos = 42