Advertisement
Guest User

Untitled

a guest
Sep 20th, 2017
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class A
  6. {
  7. public:
  8. virtual void foo() = 0;
  9.  
  10. protected:
  11. A() {}
  12. };
  13.  
  14. class A1 : public A
  15. {
  16. public:
  17. A1() : A() {}
  18.  
  19. void foo() { cout << "A1 foo" << endl; };
  20. };
  21.  
  22. class A2 : public A
  23. {
  24. public:
  25. A2() : A() {}
  26.  
  27. void foo() { cout << "A2 foo" << endl; };
  28. };
  29.  
  30. class B
  31. {
  32. public:
  33. virtual void bar() { cout << "B bar: " << endl; }
  34. };
  35.  
  36. class B1 : public B
  37. {
  38. public:
  39. void bar()
  40. {
  41. cout << "B1 bar wrapper begin" << endl;
  42. B::bar();
  43. cout << "B1 bar wrapper end" << endl;
  44. }
  45. };
  46.  
  47. /*
  48. ???
  49. pure virtual class C
  50. enforce derived classes to inherit something of type A
  51. enforce derived classes to inherit something of type B
  52.  
  53. class C1 : public A1, either B or B1 ??? templates???
  54. {
  55.  
  56. }
  57.  
  58. class C2 : public A2, either B or B1 ??? templates???
  59. {
  60.  
  61. }
  62.  
  63. Can this be done without having to define classes CA1B, CA2B, CA1B1, CA2B1, etc.?
  64. */
  65.  
  66. int main(int argc, char *argv[])
  67. {
  68. A1 a1;
  69. a1.foo();
  70. A2 a2;
  71. a2.foo();
  72.  
  73. /*
  74. C1 c1b with type B
  75. C1 c1b1 with type B1
  76. C2 c2b with type B
  77. C2 c2b1 with type B1
  78.  
  79. put c1b, c1b1, c2b, c2b1 in a list named "combinations"
  80.  
  81. cout << "Printing combinations" << endl;
  82. for (auto i : combinations)
  83. {
  84. i->foo();
  85. i->bar();
  86. }
  87. */
  88.  
  89. return 0;
  90. }
  91.  
  92. A1 foo
  93. A2 foo
  94. Printing combinations
  95. A1 foo
  96. B bar
  97. A1 foo
  98. B1 bar wrapper begin
  99. B bar
  100. B1 bar wrapper end
  101. A2 foo
  102. B bar
  103. A2 foo
  104. B1 bar wrapper begin
  105. B bar
  106. B1 bar wrapper end
  107.  
  108. template<class A_, class B,
  109. std::enable_if_t<std::is_base_of<A, A_>::value>, int> = 0,
  110. std::enable_if_t<std::is_base_of<B, B_>::value>, int> = 0>
  111. class C : public A_, public B_
  112. {
  113.  
  114. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement