<分区>
Possible Duplicate:
Where and why do I have to put the “template” and “typename” keywords?
本文转自Stroustroup's FAQ .我见过当您不知道类型时使用的类型名称,例如在模板中,template <typename> class some_class
.为什么在下面的示例中使用 typename?
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";
}