Guest User

Untitled

a guest
Jul 21st, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. typedef int data;
  2.  
  3. class data_provider {
  4.  
  5. public:
  6. virtual data get_data() = 0;
  7. };
  8.  
  9. class specific_data_provider : public data_provider {
  10. public:
  11. data get_data() {
  12. return 7;
  13. }
  14. };
  15.  
  16. class my_device {
  17. public:
  18. data_provider * dp;
  19. data d;
  20.  
  21. my_device (data_provider * adp) {
  22. dp = adp;
  23. d = 0;
  24. }
  25.  
  26. void update() {
  27. d = dp->get_data();
  28. }
  29. };
  30.  
  31. int
  32. main() {
  33. specific_data_provider sdp;
  34. my_device dev(&sdp);
  35.  
  36. dev.update();
  37.  
  38. printf("d = %dn", dev.d);
  39.  
  40. return 0;
  41. }
  42.  
  43. struct A { int x; };
  44. struct B : A { int y; };
  45. struct C { int x, y; };
  46.  
  47. struct A { virtual ~A(); };
  48. struct B : A { ... };
Add Comment
Please, Sign In to add comment