fork(3) download
  1. struct class {
  2. int a;
  3. int (*method)(struct class* this, int b, int c);
  4. };
  5.  
  6. int code(struct class* this, int b, int c) {
  7. return this->a*b+c;
  8. }
  9.  
  10. struct class constructor(int a) {
  11. struct class result = {a, code};
  12. return result;
  13. }
  14.  
  15. #define call(obj, method, ...) ((obj).method(&(obj), __VA_ARGS__))
  16.  
  17. #include <stdio.h>
  18. int main() {
  19. struct class obj = constructor(10);
  20. int result = call(obj, method, 2, 3);
  21. printf("%d\n", result);
  22. return 0;
  23. }
  24.  
Success #stdin #stdout 0s 1832KB
stdin
Standard input is empty
stdout
23