Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include<iostream>
- using namespace std;
- #define MAX 100
- template <class T> class MyVector1
- {
- private:
- int size;
- int index;
- public:
- T * array1;
- MyVector1();
- MyVector1(int size);
- int getSize();
- void push_back(const T & value);
- T & operator[](int index);
- ~MyVector1();
- };
- template<class T>
- MyVector1<T>::MyVector1()
- {
- array1 = new T[MAX];
- index = 0;
- size = MAX;
- }
- template <class T>
- MyVector1<T>::MyVector1(int max1)
- {
- array1 = new T[max1];
- index = 0;
- size = max1;
- }
- template < class T>
- void MyVector1<T>::push_back(const T & value)
- {
- if (index <= size)
- array1[index++] = value;
- else
- cout << "vector full" << endl;
- }
- template<class T>
- int MyVector1<T>::getSize()
- {
- return size;
- }
- template<class T>
- T& MyVector1<T>::operator[](int index)
- {
- return array1[index];
- }
- template<class T>
- MyVector1<T>::~MyVector1()
- {
- delete[] array1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement