I was reading this article from this page, so let me present the code:
template <class T> class D: typename C<T>::Base { //#1 error
D(): typename C<T>::Base(typename C<T>::Base(0)) { } //#2 error, #3 correct
typename C<T> f() { //#4 error
typename C<T>::A* p; //#5 correct
A<T>::B * n;
}
};
class Q{
typename C<long>::A * p; // #6 error
}
template <class T, class U> class R{
typename C<long>::A * p; // #7 optional
}
#3 is correct but I am trying to understand what the author is attempting to convey. He says:
typename #3: correct. Here, typename is used for disambiguating the
type of a parameter. Without typename, the expression C::Base(0)
would be treated as a call to a function called Base. With the
typename prefix, C::Base(0) creates a temporary object of type
C::Base initialized with the argument 0.
Also, if you see a little above that part the author says:
The typename keyword must prefix a dependent name when that name
satisfies the following three rules:1.It appears inside a template
2.It’s qualified // i am unable to understand this line at all in conjunction with starting para of this quote
3.It isn’t used in a base class specification or a member initialization
list.
I am unable to understand this line (#2 above) at all in conjunction with starting paragraph of this quote. Can you explain what the author means?
“Qualified” means that it is not in the same scope, but a subscope of the current one, which also depends on a template. For instance,
bis a qualifiedidwhen referenced in another template e.gRelevant quote from the standard (§14.6.3):
And §14.6.2:
And §14.6.7: