Possible Duplicate:
Where and why do I have to put the “template” and “typename” keywords?
This is reproduced from Stroustroup's FAQ. I've seen typename used when you don't know the type, for instance in templates, template <typename> class some_class
. Why is typename used in the example below?
template<class T> void printall(const vector<T>& v)
{
for (auto p = v.begin(); p!=v.end(); ++p)
cout << *p << "\n";
}
In C++98, we'd have to write
template<class T> void printall(const vector<T>& v)
{
for (typename vector<T>::const_iterator p = v.begin(); p!=v.end(); ++p)
cout << *p << "\n";
}