Upon request I have post the rest of the code in idone.com
So I have to create my own Vector Class and I did. It is required. When I implement it in another class however, It gives me these errors This is how I am trying to implement it:
#include "Vector.h"
class UserDB
{
private:
Vector<AccountInfo*> _accounts;
//more code that previous to this implementation worked fine.
};
I was hoping someone could tell me what to do about it. I'm completely clueless in this one. Java never gave such errors, whatsoever...
EDIT: I have also realized that when I say something like Vector<int> _accounts;
it runs completely fine, however when done with a class such as Vector, it seems almost impossible to fix it. I am reading a lot, but I still cannot seem to find a fix to this.
This is my Vector Header
#include "ArrayClass.h" //Class with more methods
#include "AbstractVector.h" //Another class with more method
template <class DT>
class Vector: virtual public ArrayClass<DT>,
virtual public AbstractVector<DT>
{
protected:
int _currSize;
int _incFactor;
public:
Vector ();
Vector (int n);
Vector (int n, DT& val);
Vector (const Vector<DT>& v);
Vector (const ArrayClass<DT>& ac);
virtual ~Vector();
void operator= (const Vector<DT>& v);
void operator= (const ArrayClass<DT>& ac);
virtual void insert (const DT& item, int index);
virtual void remove (int index);
virtual void add (const DT& item);
virtual int size() const;
virtual int capacity() const;
virtual int incFactor() const;
virtual void setIncFactor(int f);
void setCapacity(int c);
};
And this one is the Actual code Vector.cpp
#include "Vector.h"
template <class DT>
Vector<DT>::Vector () : ArrayClass<DT>()
{
_currSize = 0;
_incFactor = 5;
}
Vector<DT>::~Vector ()
{
_currSize = NULL;
_incFactor = NULL;
}
template <class DT>
Vector<DT>::Vector (int n): ArrayClass<DT>(n)
{
_currSize = 0;
_incFactor = (n+1)/2;
}
template <class DT>
Vector<DT>::Vector (int n, DT& val)
: ArrayClass<DT>(n, val)
{
_currSize = 0;
_incFactor = n/2;
}
template <class DT>
Vector<DT>::Vector (const Vector<DT>&v)
: ArrayClass<DT> (v)
{
_currSize = v._currSize;
_incFactor = v.incFactor();
}
template <class DT>
Vector<DT>::Vector (const ArrayClass<DT>& ac)
: ArrayClass<DT> (ac)
{
_currSize = ac.size();
_incFactor = (_currSize+1)/2;
}
template <class DT>
void Vector<DT>::operator= (const Vector<DT>& v)
{
ArrayClass<DT>::copy (v);
_currSize = v._currSize;
_incFactor = v.incFactor();
}
//template <class DT>
//void Vector<DT>::operator= (const ArrayClass<DT>&ac)
//{
// ArrayClass<DT>::copy (ac);
// _currSize = ac.size();
// _incFactor = (_currSize+1)/2;
//}
template <class DT>
int Vector<DT>::size() const
{
return _currSize;
}
template <class DT>
int Vector<DT>::capacity() const
{
return _size;
}
template <class DT>
int Vector<DT>::incFactor() const
{
return _incFactor;
}
template <class DT>
void Vector<DT>::add (const DT& item)
{
insert (item, _currSize);
}
template <class DT>
void Vector<DT>::setIncFactor(int f)
{
if (f >= 0) _incFactor = f;
}
template <class DT>
void Vector<DT>::setCapacity(int c)
{
int len = _currSize;
if (len > c) len = c;
DT* paNew = new DT[c];
if (paNew == NULL)
{
throw ArrayMemoryException();
}
for (int i = 0; i < len; i++)
{
paNew[i] = paObject[i];
}
if (paObject != NULL)
{
delete[] paObject;
}
paObject = paNew;
_size = c;
if (_currSize > len)
{
_currSize = len;
}
}
template <class DT>
void Vector<DT>::insert (const DT& item, int index)
{
if ((index < 0) || (index > _currSize))
{
throw ArrayBoundsException();
}
if (_currSize+1 == _size)
{
setCapacity (_size + _incFactor);
}
_currSize++;
for (int i = _currSize-1; i > index; i--)
{
(*this)[i] = (*this)[i-1];
}
(*this)[index] = item;
}
template <class DT>
void Vector<DT>::remove (int index)
{
if ((index < 0) || (index >= _currSize))
{
throw ArrayBoundsException();
}
if (_currSize <= _size-_incFactor)
{
setCapacity (_size - _incFactor);
}
for (int i = index; i < _currSize-1; i++)
{
(*this)[i] = (*this)[i+1];
}
_currSize--;
}