"Steven T. Hatton" <su******@setidava.kushan.aa> wrote in message
news:Mp********************@speakeasy.net...
Alexander Malkis wrote:
What's the semantical/syntactical difference between two keywords
"class" and "typename" (apart from different spelling)?
I don't know if anybody mentioned this, I just learned it. It is
discussed in TC++PL(SE) Appendix C.13.5. Stroustrup explains it as a way of
disambiguating statements in template declarations. For example
template<class C> void h(C& v)
{
typename C::iterator i = v.begin();
}
--
STH
Hatton's Law: "There is only One inviolable Law"
KDevelop: http://www.kdevelop.org SuSE: http://www.suse.com
Mozilla: http://www.mozilla.org
Sometimes compilers need some guidance. Typename is a way of telling the
compiler that C::iterator is a C++ Type (as opposed to a C++ function call,
for example).
You will only see typename used in contexts related to programs using
templates.
As far as how/when to use typename : use it when inside of a templated
class/function and refering to a typedef belonging to the templated
parameter. For example, C in you code above is a templated parameter.
iterator is a typedef defined in C. Therefore, you must use the typename
keyword when declaring an object of that type (or if re-typedef'ing (in C):
typedef typename C::iterator IteratorType).
NPC