Chapter 5. Tricky Basics
This chapter covers some further basic aspects of templates that are relevant to the practical use of templates: an additional use of the typename
keyword, defining member functions and nested classes as templates, template template parameters, zero initialization, and some details about using string literals as arguments for function templates. These aspects can be tricky at times, but every day-to-day programmer should have heard of them.
5.1 Keyword typename
The keyword typename
was introduced during the standardization of C++ to clarify that an identifier inside a template is a type. Consider the following example:
template <typename T> class MyClass { typename T::SubType * ptr; … };
Here, the second typename ...
Get C++ Templates: The Complete Guide 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.