Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. struct date
  5. {
  6. unsigned day;
  7. struct date *(*func[2])(struct date*);
  8. };
  9.  
  10. struct date *create_date(void)
  11. {
  12. struct date *obj = malloc(sizeof(struct date));
  13. return obj ? obj : NULL;
  14. }
  15.  
  16. struct date *assign(struct date *this, unsigned value){
  17. this->day = value;
  18. return this;
  19. }
  20. struct date* print(struct date *this){
  21. printf("%dn",this->day);
  22. return this;
  23. }
  24.  
  25. int main()
  26. {
  27. struct date *my = create_date();
  28. assign(my,13);
  29.  
  30. my->func[0] = print;
  31. my->func[1] = print;
  32.  
  33. my->func[0](my)->func[1](my);
  34.  
  35.  
  36. //print(my);
  37. free(my);
  38.  
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement