Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2014
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.93 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Dummy {
  5. public:
  6.     char val;
  7.     Dummy() { val = 'D'; }
  8.     void set(char c) { val = c; }
  9.     char get_val() { return val; }
  10. };
  11.  
  12. class DummyA : public Dummy {
  13. public:
  14.     DummyA() { val = 'A'; }
  15.     char get_a() { return 'A'; }
  16. };
  17.  
  18. class DummyB : public Dummy {
  19. public:
  20.     DummyB() { val = 'B'; }
  21.     char get_b() { return 'B'; }
  22. };
  23.  
  24. class DummyWrapper {
  25. public:
  26.     Dummy *d;
  27.     void set_d(char val) {
  28.         d = val;
  29.     }
  30. };
  31.  
  32. class DummyWrapperA : public DummyWrapper {
  33. public:
  34.     DummyWrapperA() {
  35.         d = new DummyA;
  36.     }
  37. };
  38.  
  39. class DummyWrapperB : public DummyWrapper {
  40. public:
  41.     DummyWrapperB() {
  42.         d = new DummyB;
  43.     }
  44. };
  45.  
  46. int main() {
  47.     DummyWrapperA *thing;
  48.     thing = DummyWrapperA;
  49.     cout << thing->d->get_a() << "\n";
  50.  
  51.     DummyWrapperB *thing2;
  52.     thing2 = DummyWrapperB;
  53.     cout << thing2->d->get_b() << "\n";
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement