Advertisement
yaramohamed1

Untitled

Dec 12th, 2013
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. #pragma once
  2. #include<iostream>
  3. using namespace std;
  4. #define MAX 100
  5. template <class T> class MyVector1
  6. {
  7. private:
  8. int size;
  9. int index;
  10. public:
  11. T * array1;
  12. MyVector1();
  13. MyVector1(int size);
  14. int getSize();
  15. void push_back(const T & value);
  16. T & operator[](int index);
  17. ~MyVector1();
  18. };
  19. template<class T>
  20. MyVector1<T>::MyVector1()
  21. {
  22. array1 = new T[MAX];
  23. index = 0;
  24. size = MAX;
  25. }
  26. template <class T>
  27. MyVector1<T>::MyVector1(int max1)
  28. {
  29. array1 = new T[max1];
  30. index = 0;
  31. size = max1;
  32. }
  33. template < class T>
  34. void MyVector1<T>::push_back(const T & value)
  35. {
  36. if (index <= size)
  37. array1[index++] = value;
  38. else
  39. cout << "vector full" << endl;
  40.  
  41. }
  42. template<class T>
  43. int MyVector1<T>::getSize()
  44. {
  45. return size;
  46. }
  47. template<class T>
  48. T& MyVector1<T>::operator[](int index)
  49. {
  50. return array1[index];
  51. }
  52. template<class T>
  53. MyVector1<T>::~MyVector1()
  54. {
  55. delete[] array1;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement