fork download
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3.  
  4. typedef struct{
  5. void(*Repaint)(void *);
  6. int X, Y;
  7. } Component;
  8.  
  9. void *new_Component(int x, int y){
  10. Component *this = malloc(sizeof(Component));
  11. this->X = x;
  12. this->Y = y;
  13. return this;
  14. }
  15. void delete_Component(Component *this){
  16. free(this);
  17. }
  18.  
  19. typedef struct{
  20. Component *Base;
  21. const char *Text;
  22. } Label;
  23. void Label_Repaint(void *voidthis){
  24. Label *this = voidthis;
  25. Component *base = this->Base;
  26. printf("Label \"%s\" at {%d, %d}", this->Text, base->X, base->Y);
  27. }
  28. void *new_Label(int x, int y, const char *text){
  29. Label *this = malloc(sizeof(Label));
  30. this->Base = new_Component(x, y);
  31. this->Base->Repaint = Label_Repaint;
  32. this->Text = text;
  33. return this;
  34. }
  35. void delete_Label(Label *this){
  36. delete_Component(this->Base);
  37. free(this);
  38. }
  39.  
  40. int main(void){
  41. Label *l = new_Label(1, 2, "Patrick Bateman");
  42. l->Base->Repaint(l);
  43. delete_Label(l);
  44. return 0;
  45. }
  46.  
Success #stdin #stdout 0s 2424KB
stdin
Standard input is empty
stdout
Label "Patrick Bateman" at {1, 2}