Advertisement
Guest User

Untitled

a guest
Jan 20th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. template <typename T>
  6. class Container
  7. {
  8.  protected:
  9. T * storage;
  10. size_t num_items;
  11. size_t storage_size;
  12.  public:
  13. virtual void operator += (const T item) { }
  14. virtual ~Container() { }
  15. Container() : storage(nullptr), num_items(0), storage_size(0) { }
  16. T & operator [] (size_t index)
  17.  {
  18.  if (index < num_items)
  19.  return storage[index];
  20.  }
  21. size_t size() { return num_items; }
  22. };
  23.  
  24. void main(int argc, char* argv[])
  25. {
  26.  Container<long> * store = new Box(); // Συμπληρώστε την αρχικοποίηση
  27.  // αντικειμένου της δικής σας κλάσης
  28.  *store+=10L;
  29.  *store+=20L;
  30.  *store+=30L;
  31.  for (size_t i=0; i<store->size(); i++)
  32. std::cout << (*store)[i] << " ";
  33.  std::cout << std::endl;
  34.  delete store;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement