fork download
  1. #include <iostream>
  2. #include <sstream>
  3. #include <list>
  4. #include <vector>
  5. //using namespace std;
  6. #include <string> // modified this
  7.  
  8. template<typename T, typename R>
  9. class tContainer_t
  10. {
  11. R Container;
  12. public:
  13. tContainer_t();
  14. ~tContainer_t();
  15.  
  16. bool IsEmpty();
  17. T GetFirst();
  18. T GetLast();
  19. int Size();
  20. void Insert(T* element);
  21. std::string Print();
  22.  
  23. };
  24.  
  25. template<typename T, typename R>
  26. std::string tContainer_t<T, R>::Print()
  27. {
  28. std::ostringstream s;
  29. s << "[";
  30. for(auto it = Container.begin(); it != Container.end(); it++) // modified this
  31. {
  32. s << (**it);
  33. }
  34. return s.str();
  35. }
  36.  
  37. template<typename T, typename R>
  38. void tContainer_t<T, R>::Insert( T* element )
  39. {
  40. Container.push_back(element);
  41. }
  42.  
  43. template<typename T, typename R>
  44. int tContainer_t<T, R>::Size()
  45. {
  46. return Container.size(); // modified this
  47. }
  48.  
  49. template<typename T, typename R>
  50. T tContainer_t<T, R>::GetLast()
  51. {
  52. //R<T*>::const_iterator it = Container.end();
  53. return Container.end();
  54. }
  55.  
  56. template<typename T, typename R>
  57. T tContainer_t<T, R>::GetFirst()
  58. {
  59.  
  60. }
  61.  
  62. template<typename T, typename R>
  63. bool tContainer_t<T, R>::IsEmpty()
  64. {
  65. Container.empty(); // modified this
  66. }
  67.  
  68. //CTOR
  69. template<typename T, typename R>
  70. tContainer_t<T, R>::tContainer_t() : Container()
  71. {
  72.  
  73. }
  74. //DTOR
  75. template<typename T, typename R>
  76. tContainer_t<T, R>::~tContainer_t()
  77. {
  78.  
  79. }
  80.  
  81. int main()
  82. {
  83. tContainer_t<int, std::list<int*> > l;
  84. int i1 = 1;
  85. int i2 = 2;
  86. l.Insert(&i1);
  87. l.Insert(&i2);
  88. std::cout << l.Print(); // modified this
  89. return 0;
  90. }
Success #stdin #stdout 0s 2964KB
stdin
Standard input is empty
stdout
[12