#include "Vector.h"
//Constructors
template <class T>
Vector<T>::Vector(){
arr [0];
}
template <class T>
Vector<T>::Vector(int n, const T& val){
T arr [n];
for(int i = 0; i<n; i++){
arr[i] = val;
}
}
template <class T>
Vector<T>::Vector(const Vector<T>& v){
arr = v;
}
//Deconstructor
template <class T>
Vector<T>::~Vector(){
delete arr;
}
//Methods
//Size will get the size of the array
template <class T>
unsignedint Vector<T>::size(){
int total;
while(arr){
total++;
}
return total;
}
//Push_back will add a value to the end
template <class T>
void Vector<T>::push_back(const T& elt){
int nelts, index = 0;
//Acquire size
nelts = arr.size();
//We need a temp copy
T temp[nelts];
while(arr){
temp[index] = arr[index];
index++;
}
//We change the array
index = 0;
T *arr = new Vector[nelts+1];
while(temp){
arr[index] = temp[index];
index++;
}
//Add the last value
arr[index] = elt;
}
//Pop_back will delete the last value
template <class T>
void Vector<T>::pop_back(){
int nelts, index = 0;
//Acquire size
nelts = arr.size();
//We need a temp copy
T temp[nelts];
while(arr){
temp[index] = arr[index];
index++;
}
//We change the array
index = 0;
T *arr = new Vector[nelts-1];
while(arr){
arr[index] = temp[index];
index++;
}
}
//Pop_back will delete the last value
template <class T>
T& Vector<T>::at(int pos){
return &arr[pos];
}
I'm trying to construct an array with 5 copies of 13.