|
From: Ioannis V. <iv...@in...> - 2003-03-11 03:09:49
|
-----------------------Original Message-----------------------
>From: Robson Bernard [mailto:rob...@su...]
>To: C++ Mail List [mailto:dev...@li...]
>Date: 11/3/2003 3:03:00 =F0=EC
>Subject: [Dev-C++] Scope in Template
>
>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.=20
vector is optimized in space/time for regular use. Yours will be less
flexible and less efficient.
There are other containers too you know, including valarray.
> 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=3D (const Table & a);
> T& operator[] (long index) {return ptrToArray[index];};
> long size() {return tableSize;};
> void erase(long index);
> void push(T& newObject);
>};
template<class T>
>void Table<T>::push(T& newObject)
>{
> T *temp =3D new T[tableSize + 1];
>
> for(long loopIndex =3D 0; loopIndex < tableSize; loopIndex++)
> temp[loopIndex] =3D ptrToArray[loopIndex];
>
> tableSize++;
>
> temp[tableSize - 1] =3D newObject;
>
> delete[] ptrToArray;
>
> T *ptrToArray =3D new T[tableSize];
>
> for(long loopIndex =3D 0; loopIndex < tableSize; loopIndex++)
> ptrToArray[loopIndex] =3D temp[loopIndex];
>
> delete[] temp;
>}
>
>
>
>template <class T>
>void Table<T>::erase(long index)
>{
> for(long loopIndex =3D index; loopIndex < tableSize - 1; loopIndex++=
)
> ptrToArray[loopIndex] =3D ptrToArray[loopIndex + 1];
>
> delete &ptrToArray[tableSize - 1];
> tableSize--;
>}
>
>
>
>template <class T>
>Table<T>::Table(int numberOfElements)
>{
> tableSize =3D numberOfElements;
> ptrToArray =3D new T[tableSize];
>}
>
>
>
>template <class T>
>Table<T>::Table(const Table & a)
>{
> tableSize =3D a.tableSize;
> T *ptrToArray =3D new T[tableSize];
>
> for(long loopIndex =3D 0; loopIndex < tableSize; loopIndex++)
> ptrToArray[loopIndex] =3D a.ptrToArray[loopIndex];
>}
>
>
>
>template <class T>
>T& Table<T>::operator=3D (const Table & a)
>{
> if(this =3D=3D &a) return *this;
> delete[] ptrToArray;
>
> tableSize =3D a.tableSize;
> T *ptrToArray =3D new T[tableSize];
>
> for(long loopIndex =3D 0; loopIndex < tableSize; loopIndex++)
> ptrToArray[loopIndex] =3D a.ptrToArray[loopIndex];
>
> return *this;
>}
>
>
>
>template <class T>
>Table<T>::~Table()
>{
> delete[] ptrToArray;
>}
Ioannis Vranos=20
* Programming pages: http://www.noicys.freeurl.com
* Alternative URL: http://run.to/noicys=20
|