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. typename R::const_iterator it;
  31. for(it = Container.begin(); it != Container.end(); it++) // modified this
  32. {
  33. s << (**it);
  34. }
  35. return s.str();
  36. }
  37.  
  38. template<typename T, typename R>
  39. void tContainer_t<T, R>::Insert( T* element )
  40. {
  41. Container.push_back(element);
  42. }
  43.  
  44. template<typename T, typename R>
  45. int tContainer_t<T, R>::Size()
  46. {
  47. return Container.size(); // modified this
  48. }
  49.  
  50. template<typename T, typename R>
  51. T tContainer_t<T, R>::GetLast()
  52. {
  53. //R<T*>::const_iterator it = Container.end();
  54. return Container.end();
  55. }
  56.  
  57. template<typename T, typename R>
  58. T tContainer_t<T, R>::GetFirst()
  59. {
  60.  
  61. }
  62.  
  63. template<typename T, typename R>
  64. bool tContainer_t<T, R>::IsEmpty()
  65. {
  66. Container.empty(); // modified this
  67. }
  68.  
  69. //CTOR
  70. template<typename T, typename R>
  71. tContainer_t<T, R>::tContainer_t() : Container()
  72. {
  73.  
  74. }
  75. //DTOR
  76. template<typename T, typename R>
  77. tContainer_t<T, R>::~tContainer_t()
  78. {
  79.  
  80. }
  81.  
  82. int main()
  83. {
  84. tContainer_t<int, std::list<int*> > l;
  85. int i1 = 1;
  86. int i2 = 2;
  87. l.Insert(&i1);
  88. l.Insert(&i2);
  89. std::cout << l.Print(); // modified this
  90. return 0;
  91. }
Success #stdin #stdout 0s 2964KB
stdin
Standard input is empty
stdout
[12