All my function work besides one, and it is because I can't find whats wrong with my syntax on line 22, could someone please help me? I know it has to be a simple solution that I am overlooking.
#include "Vector.h"
#include <iostream>
using namespace std;
const int zero = 0;
using namespace cop4530;
template<typename T>
Vector<T>::Vector( ) : theSize(zero), theCapacity(zero), array(NULL)
{
}
template<typename T>
Vector<T>::Vector(const Vector &rhs)
{
this = (rhs);
}
//prototype
//explicit Vector(int num, const T& val = T());
template<typename T>
Vector<T>::Vector(int num, const T& val = T())
{
}
template<typename T>
Vector<T>::~Vector()
{
delete [] array;
}
template<typename T>
const Vector<T> & Vector<T>::operator=(const Vector &rhs)
{
if (this != &rhs)
{
delete [] array;
theSize = rhs.size();
theCapacity = rhs.theCapacity();
array = new T[capacity()];
for (int i = 0; i < size(); i++)
array[i]= rhs.array[i];
}
return *this;
}
template<typename T>
T& Vector<T>::operator[](int index)
{
return array[index];
}
template<typename T>
const T& Vector<T>::operator[] (int index) const
{
return array[index];
}
template<typename T>
Vector<T>::Vector(const_iterator start, const_iterator end)
{
}
template<typename T>
T& Vector<T>::at(int loc )
{
if(loc < zero || loc >= theSize)
throw std::out_of_range("loc<0 or loc>=theSize");
return array[loc];
}
template<typename T>
const T& Vector<T>::at(int loc ) const
{
if(loc < zero || loc >= theSize)
throw std::out_of_range("loc<0 or loc>=theSize");
return array[loc];
}
template<typename T>
T& Vector <T>::front()
{
return array[zero];
}
template<typename T>
T& Vector <T>::back()
{
return array[theSize - 1];
}
template<typename T>
const T& Vector<T>::front() const
{
return array[zero];
}
template<typename T>
const T& Vector<T>::back() const
{
return array[theSize - 1];
}
template<typename T>
int Vector <T>::size() const
{
return theSize;
}
template<typename T>
int Vector <T>::capacity() const
{
return theCapacity;
}
template<typename T>
bool Vector<T>::empty() const
{
return size() == zero;
}
template<typename T>
void Vector<T>::push_back(const T & val)
{
if (theSize + 1 == theCapacity)
{
doubleCapacity(); //double capacity function
T * temp;
temp = new T[theSize];
for (int i =zero; i < theSize; i++)
temp[i] = array[i];
delete [] array;
array = new T[theCapacity];
for (int i =zero; i < theSize; i++)
array[i] = temp[i];
array[theSize] = val;
delete [] temp;
theSize++;
}
else
{
array[theSize] = val;
theSize++;
}
}
template<typename T>
void Vector<T>::pop_back()
{
theSize--;
}
//???
template<typename T>
void Vector<T>::reserve(int size)
{
if (size > theSize)
return;
T *newarray = array;
array = new T[size];
for (int i = zero; i < theSize ; i++)
array[i] = newarray[i];
theSize = size;
delete [] newarray;
}
template<typename T>
void Vector<T>:: doubleCapacity()
{
2*theCapacity;
}
template<typename T>
void Vector<T>::clear()
{
if (array != NULL)
{
delete [] array;
array = NULL;
theSize = zero;
theCapacity = zero;
}
}
template<typename T>
typename Vector<T>::iterator Vector <T>::begin()
{
return array;
}
template<typename T>
typename Vector<T>::iterator Vector <T>::end()
{
return array + size();
}