Reputation: 5793
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();
...
...
}
};
Upvotes: 3
Views: 116
Reputation: 94329
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();
Upvotes: 6