metodes in template class arn't recognize
-
I have in my project a template class. When I try to use a method in that class, then i get error messages like that: C:\My Documents\tel_op3\tel_op3\info_dlg.cpp(14) : error C2228: left of '.setFilename' must have class/struct/union type What could be the problem? Thanks, Chen
-
I have in my project a template class. When I try to use a method in that class, then i get error messages like that: C:\My Documents\tel_op3\tel_op3\info_dlg.cpp(14) : error C2228: left of '.setFilename' must have class/struct/union type What could be the problem? Thanks, Chen
Include the header file of the class in the cpp file. If this doesn't work, give more details because it is impossible to know what's happening with so little clues.
-
Include the header file of the class in the cpp file. If this doesn't work, give more details because it is impossible to know what's happening with so little clues.
I included the header file of the template class in the header of the class that use it, adding it to the cpp file doesn't help (i get the same error messages). Details: I wrote a template class that represent a list of objects. this it's definition:
template< class T > class obj_list { public: obj_list(); virtual ~obj_list(); void addObject(T *object); T getObjectAt(int i); void saveObjects(); int getNumOfObjects(); void close_file(); void setFilename(char *fileName); private: char* file_name; CObList objects; POSITION pos; CFile objects_file; int numOfObjects; };
It's implication came in the same header file (i heard that when i writing a template class I need to put the definition and implication in the header file). I have a class named info_dlg, and in it's header file I create a variable of the type of obj_list, by writing this line: obj_list user_s(); (user_info is a class that hold information about a user). In the cpp of info_dlg, I have some methods that in them I try to use some of obj_list's methods, but i get error messages like that: C:\My Documents\tel_op3\tel_op3\info_dlg.cpp(14) : error C2228: left of '.setFilename' must have class/struct/union type C:\My Documents\tel_op3\tel_op3\info_dlg.cpp(21) : error C2228: left of '.saveObjects' must have class/struct/union type C:\My Documents\tel_op3\tel_op3\info_dlg.cpp(41) : error C2228: left of '.addObject' must have class/struct/union type I hope this is enough details, and you could help me. Chen