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> >)':;’ before “it”
SO_template.cpp:44: error: expected
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>::iteratoris a “dependent type” – the whole type depends onT. Prefix this withtypenameto fix the issue, so make the line read