Appendix B. The typename and template Keywords

The template keyword is used to introduce template declarations and definitions:

   template <class T>   class vector;

The typename keyword is often used in place of class to declare template type parameters:1

   template <typename T>   class vector;

Both keywords also have a second role in the language. This appendix is about that role, why it is needed, and exactly how to apply typename and template to fill it. Because the rules are subtle, many people wait until the compiler complains before thinking about the use of typename or template, but it’s worth learning these technical details because:

• You’ll spend less time fixing trivial syntax errors.

• You’ll understand what you did wrong when ...

Get C++ Template Metaprogramming: Concepts, Tools, and Techniques from Boost and Beyond now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.