C ++, template argument error

Below is my template matrix that I want to build, taking a value from a user. But when I compile it. I am getting below error. Why a mistake?

SO_template.cpp: In a member function void Matrix<T>::BuildMatrix(std::vector<T, std::allocator<_CharT> >)': SO_template.cpp:44: error: expected

; 'to "it"

If I specialize my class using int it doesn't complain, why?

 template<class T>
  class Matrix
          vector<T> col;
          int iNumberOfRow;
          int iNumberOfCol;
     void BuildMatrix(const std::vector<T> stringArray)

         std::vector<T>::iterator it= stringArray.begin();
         cout<<"Build Matrix irow="<<stringArray.size();



source to share

1 answer

The problem is what std::vector<T>::iterator

is "type dependent" - the whole type depends on T

. Prefix this with typename

to fix the problem, so read the line

typename std::vector<T>::iterator it= stringArray.begin();




All Articles