Guest User

Untitled

a guest
Jun 17th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. class C1 {
  2. public:
  3. void foo();
  4. }
  5.  
  6. class C2 {
  7. public:
  8. void foo();
  9. }
  10.  
  11. class Derived1 : public Base {
  12. public:
  13. void Update() {
  14. member.foo();
  15. }
  16. private:
  17. C1 member;
  18. }
  19.  
  20. class Derived2 : public Base {
  21. public:
  22. void Update() {
  23. member.foo();
  24. }
  25. private:
  26. C2 member;
  27. }
  28.  
  29. template <class T>
  30. class CTemplateBase
  31. {
  32. public:
  33. void Update()
  34. {
  35. member.foo();
  36. }
  37. private:
  38. T member; // Generic type
  39. }
  40.  
  41. class CDerived1 : public CTemplateBase<C1>
  42. {
  43. // No common algorithms required here
  44. }
  45.  
  46. class CDerived2 : public CTemplateBase<C2>
  47. {
  48. // No common algorithms required here
  49. }
  50.  
  51. template <class T>
  52. class Derived : public Base {
  53. public:
  54. void Update() {
  55. member.foo();
  56. }
  57. private:
  58. T member;
  59. }
  60.  
  61. class IFooable {
  62. public:
  63. virtual void foo() = 0;
  64. }
  65.  
  66. class C1 : IFooable {
  67. public:
  68. void foo();
  69. }
  70.  
  71. class C2 : IFooable {
  72. public:
  73. void foo();
  74. }
  75.  
  76. class Base {
  77. public:
  78. void Update() {
  79. member->foo();
  80. }
  81. private:
  82. IFooable* member
  83. }
  84.  
  85. class Derived1 : public Base {
  86. Derived1 () : member(new C1()) {}
  87. ~Derived1 () { delete member; }
  88. }
  89.  
  90. class Derived2 : public Base {
  91. Derived2 () : member(new C2()) {}
  92. ~Derived2 () { delete member; }
  93. }
Add Comment
Please, Sign In to add comment