|
From: Robson B. <rob...@su...> - 2003-03-11 00:39:42
|
Hello all c++ coders!
I am working on a substitute for the vector template - <ctable> - due to
some extra kbytes that <vector> increases in the exe file. In the 'push'
member function of my class template, named 'Table', i get the following
error for line 20 when compiling:
20 'T' was not declared in this scope
20 template argument 1 is invalid
20 'T' was not declared in this scope
20 parse error before ')'
Please HELP ME!!!
the class:
template <class T>
class Table
{
T *ptrToArray;
long tableSize;
public:
Table(int numberOfElements);
Table(const Table & a);
~Table();
T& operator= (const Table & a);
T& operator[] (long index) {return ptrToArray[index];};
long size() {return tableSize;};
void erase(long index);
void push(T& newObject);
};
void Table<T>::push(T& newObject)
{
T *temp = new T[tableSize + 1];
for(long loopIndex = 0; loopIndex < tableSize; loopIndex++)
temp[loopIndex] = ptrToArray[loopIndex];
tableSize++;
temp[tableSize - 1] = newObject;
delete[] ptrToArray;
T *ptrToArray = new T[tableSize];
for(long loopIndex = 0; loopIndex < tableSize; loopIndex++)
ptrToArray[loopIndex] = temp[loopIndex];
delete[] temp;
}
template <class T>
void Table<T>::erase(long index)
{
for(long loopIndex = index; loopIndex < tableSize - 1; loopIndex++)
ptrToArray[loopIndex] = ptrToArray[loopIndex + 1];
delete &ptrToArray[tableSize - 1];
tableSize--;
}
template <class T>
Table<T>::Table(int numberOfElements)
{
tableSize = numberOfElements;
ptrToArray = new T[tableSize];
}
template <class T>
Table<T>::Table(const Table & a)
{
tableSize = a.tableSize;
T *ptrToArray = new T[tableSize];
for(long loopIndex = 0; loopIndex < tableSize; loopIndex++)
ptrToArray[loopIndex] = a.ptrToArray[loopIndex];
}
template <class T>
T& Table<T>::operator= (const Table & a)
{
if(this == &a) return *this;
delete[] ptrToArray;
tableSize = a.tableSize;
T *ptrToArray = new T[tableSize];
for(long loopIndex = 0; loopIndex < tableSize; loopIndex++)
ptrToArray[loopIndex] = a.ptrToArray[loopIndex];
return *this;
}
template <class T>
Table<T>::~Table()
{
delete[] ptrToArray;
}
|