On Feb 7, 5:12 pm, Juha Nieminen <nos...@thanks.invalid> wrote:
> Bo Persson <b...@gmb.dk> wrote:
> > That the compiler cannot formally know that
> > std::vector<A<U>>::const_iterator is a type (because someone could
> > specialize std::vector for some user defined types). You have to add a
> > 'typename' to specify what it is:
> Is there any conrete example where the same dependent name could be
> used as both a type name and a non-type name, and this could potentially
> cause confusion? Why exactly is the 'typename' keyword necessary?
extern int p;
template<typename T>
struct S : B<T>
{
B<T>:

* p; // marked statement
};
If B<T>:

is the name of a type, the marked statement is a
declaration of a pointer to that type. If it is the name of a
constant or a variable, the marked statement is an expression
statement, and the * is multiplication.
In a lot of cases, context would allow the compiler to make it
clear: only a type is legal, or a type is not legal, but the
committee decided to not require the compiler to take any
context into consideration.
--
James Kanze