fork(1) download
  1.  
  2. #include <vector>
  3. #include <list>
  4. #include <string>
  5.  
  6. template <class Type>
  7. class Base {
  8. protected:
  9. std::string line;
  10. public:
  11. Base();
  12. //Type histories [2];
  13. std::string DisplayHistory();
  14. std::string DisplayRecent();
  15. };
  16.  
  17. class DerivedA : public Base<T> {
  18. //error: 'T' was not declared in this scope
  19. //error: template argument 1 is invalid
  20. protected:
  21. std::string last;
  22. std::string combined;
  23. std::list<std::string> A;
  24. public:
  25. DerivedA();
  26. void Add(std::string line);
  27. std::string DisplayHistory();
  28. };
  29.  
  30. class DerivedB : public Base<T> {
  31. protected:
  32. std::string last;
  33. std::string combined;
  34. std::vector<std::string> B;
  35. public:
  36. DerivedB();
  37. void Add(std::string line);
  38. std::string DisplayHistory();
  39. };
  40.  
  41.  
  42.  
  43. template <class T>
  44. Base<T>::Base()
  45. {
  46. histories[0] = DerivedA();
  47. histories[1] = DerivedB();
  48. }
  49.  
  50. template <class T>
  51. std::string Base<T>::DisplayHistory()
  52. {
  53. return histories[0].DisplayHistory() + "\n" + histories[1].DisplayHistory();
  54. }
  55.  
  56. template <class T>
  57. std::string Base<T>::DisplayRecent()
  58. {
  59. return last;
  60. }
  61.  
  62. DerivedA::DerivedA()
  63. {
  64. combined = "List History:\n";
  65. }
  66.  
  67. void DerivedA::Add(std::string line)
  68. {
  69. if (A.size() <= 50)
  70. {
  71. A.push_front(line);
  72. }
  73. else
  74. {
  75. A.pop_back();
  76. A.push_front(line);
  77. }
  78. last = line;
  79. }
  80.  
  81. std::string DerivedA::DisplayHistory()
  82. {
  83. for (int n = A.size(); n > 0; n--)
  84. {
  85. combined.append(A[n]);
  86. combined.append("\n");
  87. }
  88. return combined;
  89. }
  90.  
  91. DerivedB::DerivedB()
  92. {
  93. combined = "STD:Vector List History:\n"
  94. }
  95.  
  96. void DerivedB::Add(std::string line)
  97. {
  98. if (B.size() <= 50)
  99. {
  100. B.push_front(line);
  101. }
  102. else
  103. {
  104. B.pop_back();
  105. B.push_front(line);
  106. }
  107. last = line;
  108. }
  109.  
  110. std::string DerivedB::DisplayHistory()
  111. {
  112. for (int n = B.size(); n > 0; n--)
  113. {
  114. combined.append(B[n]);
  115. combined.append("\n");
  116. }
  117. return combined;
  118. }
  119.  
  120.  
  121.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty