According to this question, typename
should be added to tell compiler that iterator
is a type (Is it correct?), e.g.
template <typename T>
void print(vector<T> &v) {
for (typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
cout<<*it<<endl;
}
Two questions:
Under what circumstances should a
typename
be added? Can someone give me another example?Can
auto
in C++11 replace all thesetypename xxx
cases?