0

I am wondering why we need to had the typename keyword or not in these two situations :

template <T>
void foo(void)
{
   std::vector<T> v;
   typename std::vector<T>::iterator it;
}

In the case of an iterator the compiler send us an error if typename is not specified.

Thank you !

Alex
  • 11
  • 2

1 Answers1

0

From the C++ 17 Standard (17.7 Name resolution)

2 A name used in a template declaration or definition and that is dependent on a template-parameter is assumed not to name a type unless the applicable name lookup finds a type name or the name is qualified by the keyword typename.

Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335