Question/problem regarding to templates in C++
-
I wrote a template class that represents objects list. This is its header:
template< class T, char* filename >
class obj_list
{
public:
obj_list();
virtual ~obj_list();
void addObject(T *object);
T getObjectAt(int i);
void saveObjects();
int getNumOfObjects();
void close_file();
private:
CObList objects;
POSITION pos;
CFile objects_file;
int numOfObjects;};
When I want to create an object of the type of this class, by writing this line:
obj_list users
I get this error message: c:\my documents\tel_op3\tel_op3\info_dlg.h(19) : error C2964: invalid expression as template parameter that point on that line and that error message: c:\my documents\tel_op3\tel_op3\obj_list.h(13) : error C2973: 'obj_list' : invalid template argument 'filename' that point on the first line in the header (the one that conation '{') The template class passes the compile without any error message. What is wrong and how can i fix it? Thanks in advance, Chen. -- modified at 6:18 Wednesday 31st August, 2005
-
I wrote a template class that represents objects list. This is its header:
template< class T, char* filename >
class obj_list
{
public:
obj_list();
virtual ~obj_list();
void addObject(T *object);
T getObjectAt(int i);
void saveObjects();
int getNumOfObjects();
void close_file();
private:
CObList objects;
POSITION pos;
CFile objects_file;
int numOfObjects;};
When I want to create an object of the type of this class, by writing this line:
obj_list users
I get this error message: c:\my documents\tel_op3\tel_op3\info_dlg.h(19) : error C2964: invalid expression as template parameter that point on that line and that error message: c:\my documents\tel_op3\tel_op3\obj_list.h(13) : error C2973: 'obj_list' : invalid template argument 'filename' that point on the first line in the header (the one that conation '{') The template class passes the compile without any error message. What is wrong and how can i fix it? Thanks in advance, Chen. -- modified at 6:18 Wednesday 31st August, 2005
use the [Modify][^] link at the bottom of your post to edit it, and the, uncheck the 'Do not treat <'s as HTML tags' check box. moreover, put the code inside a
<pre></pre>
block to let us benefit of the indentation...
TOXCCT >>> GEII power
[toxcct][VisualCalc] -- modified at 6:13 Wednesday 31st August, 2005