Topic: keyword typename
Author: 100754.2730@compuserve.com (Martin Aupperle)
Date: 1996/05/30 Raw View
In the following example
template< class T > f( T ) {
typename T::X x = 35;
/* ... */
}
why is it necessary to use the keyword typename?
I thought the new standard says that binding of a name occurs at
instantiation time, if the name depends on a template argument.
So, this is the case here for X, and f should be instantiated when T
is known. But then we have no problem determining what X is.
Where is the rationale for the keyword typename then?
[Moderator's reply: although the name is *bound* at
instantiation time, the code is *parsed* when it is first
encountered. Because of a long-standing ambiguity in the
grammar of C, the compiler needs to know whether nor not a name
is a type name in order to merely parse it. In C, this is
normally handled by some sort of feedback from the compiler
to the lexer. But in C++ templates, sometimes even that is
not enough, and so an explicit `typename' is required to resolve
the ambiguity. -fjh.]
Martin
-----------------------------------
Signatures are a waste of bandwidth
-----------------------------------
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]