‘typename’ is not always a substitute for ‘class’ in a template parameter

You know the C++ rule that says that the keyword ‘typename’ can be used interchangably with ‘class’ in a template parameter?  Not always!  Not for the keyword ‘class’ that appears after the template parameter of a template template parameter!

This is a syntax error:

You must write it like this:

Why is that?  Jonathan Caves explains here that the rule ‘typename’ can be used interchangably with ‘class’ is a semantic rule, but the use of ‘class’ in the template template parameter is a syntax rule, and thus takes precedence.

Oversight? Intentional?

By the way, Visual C++ 2012 gives a really unhelpful pair of error messages for this, one of which includes an internal grammar rule name—and that is really non-optimal for a compiler error message:

0 Responses to “‘typename’ is not always a substitute for ‘class’ in a template parameter”


  • No Comments

Leave a Reply