I'm trying to create a class template for arrays. The code mostly compiles ok except for the overloaded [] operator. This gives a C 2955 error in MSVC 6, but I don't understand why. The help file wasn't much help. Any ideas? Code below. Thanks.
Header File
Implementation FileCode:#include <iostream> using namespace std; template <class T> class t_Array { public: t_Array(int = 10); virtual ~t_Array(); T &operator[](int); private: T *ptr; int size; };
Error MessageCode:#include <iostream> #include <cassert> using namespace std; #include "t_Array.h" ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// template <class T> t_Array<T>::t_Array(int arraySize) { size = (arraySize > 1 ? arraySize : 10); ptr = new T[size]; assert(ptr != 0); } template <class T> t_Array<T>::~t_Array() { delete [] ptr; } template <class T> T &t_Array::operator[](int subscript) // This is line 30 in error msg { assert(1 <= subscript && subscript < size); return ptr[subscript]; }
t_Array.cpp
d:\documents and settings\cis-staff\desktop\greg\t_array\t_array.cpp(30) : error C2955: 't_Array' : use of class template requires template argument list
d:\documents and settings\cis-staff\desktop\greg\t_array\t_array.h(26) : see declaration of 't_Array'



LinkBack URL
About LinkBacks


