   Using templates as a vector type
template <class T>class DataFile{private:std::vector <T*> data;// worksstd::vector <int>::iterator vector_int;   // worksstd::vector <T*>::iterator current;  // does not work...for ( std::vector<T*>::iterator itr = data.begin(); itr != data.end(); itr++ )...class DFBooks : public DataFile <Book> {I am getting the errors:error: expected ‘;’ before ‘current’datafile.h:46: error: expected `;' before ‘itr’dfbooks.h:16:   instantiated from here **this is the class DFBooks line**datafile.h:46: error: dependent-name ‘std::vector<T*,std::allocator<T*> >::iterator’ is parsed as a non-type, but instantiation yields a typedatafile.h:46: note: say ‘typename std::vector<T*,std::allocator<T*> >::iterator’ if a type is meantI don't understand what is meant by the last couple of error messages. I'm using GCC with Code::Blocks.Can I not use a templated class with a vector iterator?   
  The iterator class depends on the template parameter, therefore you need to prefix it with typename. Like this:template <class T>class DataFile{private:std::vector <T*> data;// worksstd::vector <int>::iterator vector_int;   // workstypename std::vector <T*>::iterator current;EDIT: The reason int works is that std::vector doesn't depend on a template parameter, but int.   ;  To add to what CTar said said, with std::vector<T*> the compiler doesn't yet know what T is and therefore cannot know what std::vector<T*>::iterator is (thanks to template specialisation).  Hence, you need to explicitly tell the compiler it should be a type (using the typename keyword).EDIT: Although you can get away with it with some older non-conforming compilers, those same compiler will give you many pages of obscure and near impossible to track down error messages when it does cause problems.;Quote:Original post by RhysBJdatafile.h:46: error: dependent-name ‘std::vector<T*,std::allocator<T*> >::iterator’ is parsed as a non-type, but instantiation yields a typedatafile.h:46: note: say ‘typename std::vector<T*,std::allocator<T*> >::iterator’ if a type is meantI don't understand what is meant by the last couple of error messages. Can I not use a templated class with a vector iterator?The previous posters explained the problem, but I'd like to point out that the compiler's error messages literally spelled it out for you: as a dependent name (something that depends on a yet-unspecified template parameter) vector<T*>::iterator is interpreted by the compiler as a value (a static member variable), but you are using it as if it were a nested type. The compiler cannot know whether the error is in the usage: you really meant to use a static member but syntax errors caused it to be read as using a nested type; or if the usage is correct and vector<T*>::iterator should be interpreted as a nested type: which it tells you can be done by adding the typename keyword.template<class T> struct Foo{   vector<int>::iterator a;   // non-dependent type, the compiler can look // the correct definition up and see it is a// nested type   vector<T>::iterator b;// dependent type, the compiler must assume// it is a static member variable and will// flag it as a syntax error.   typename vector<T>::iterator c; // dependent type, you told the compiler it// is a nested type, so the code will compile// without a problem.};;Quote:datafile.h:46: note: say ‘typename std::vector<T*,std::allocator<T*> >::iterator’ if a type is meantSee, the nice compiler even gave you the fix for your problem.