Advertisement
Guest User

Vector.h

a guest
Apr 24th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1. #ifndef VECTOR_H
  2. #define VECTOR_H
  3.  
  4. #include <iostream>
  5. #include <new>
  6. #include <stdbool.h>
  7.  
  8. using namespace std;
  9.  
  10. template <class T>
  11. class Vector
  12. {
  13.     public:
  14.         int* arr = new int[DEFAULT_CAPACITY];
  15.  
  16.         if (arr == nullptr) {
  17.             cout << "Error: memory could not be allocated";
  18.         }
  19.        
  20.         void incrementarr() {
  21.             int n = sizeof(arr);
  22.             int* controlarr = new int[n + 1];
  23.             for (int i = 0; i < n; i++) {
  24.                 controlarr[i] = arr[i];
  25.             }
  26.             size++;
  27.             arr = controlarr;
  28.             delete[] controlarr;
  29.         }
  30.  
  31.         void clearArray() {
  32.             for (int i = 0; i < sizeof(arr); i++) {
  33.                 arr[i] = nullptr;
  34.             }
  35.             size = 0;
  36.             delete[] arr;
  37.         }
  38.  
  39.     private:
  40.         const static int DEFAULT_CAPACITY = 50;
  41.         int size = sizeof(arr); //keeping track of number of elements in use
  42. };
  43. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement