typename vs class in C++
Is there a difference?
NO!
There is no difference. For naming template parameters, typename
and class
are equivalent.
typename
however is possible in another context when using templates - to hint at the compiler that you are referring to a dependent type. §14.6.2:
A name used in a template declaration or definition and that is dependent on a template-parameter is assumed not to name a type unless the applicable name lookup finds a type name or the name is qualified by the keyword
typename
.
But, pre-C++98 only class
was allowed, but that was a long time ago!
However, some people would argue that semantically it would make more sense to use one keyword over another.
Thanks! You can always email me or use contact form for more questions/comments etc.