简体   繁体   中英

C++, template argument error

Below is my Template matrix which I want to build by taking value from user. But when I compile it. I am getting below error. Why the error ?

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

If I specialize my class using int it does not complain why?

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

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

The issue is that std::vector<T>::iterator is a "dependent type" - the whole type depends on T . Prefix this with typename to fix the issue, so make the line read

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM