C++ template typename iterator

In list<tNode<T>*>::iterator, you have a dependant name, that is, a name that depends on a template parameter. As such, the compiler can’t inspect list<tNode<T>*> (it doesn’t have its definition at this point) and so it doesn’t know whether list<tNode<T>*>::iterator is either a static field or a type. In such a situation, the compiler assumes that … Read more

Why is the keyword “typename” needed before qualified dependent names, and not before qualified independent names?

A name in C++ can pertain to three different tiers of entities: Types, values, and templates. struct Foo { typedef int A; // type static double B; // value template <typename T> struct C; // template }; The three names Foo::A, Foo::B and Foo::C are examples of all three different tiers. In the above example, … Read more

Why do I need to use typedef typename in g++ but not VS?

The typename is required by the standard. Template compilation requires a two step verification. During the first pass the compiler must verify the template syntax without actually supplying the type substitutions. In this step, std::map::iterator is assumed to be a value. If it does denote a type, the typename keyword is required. Why is this … Read more

tech