Item 51. Disambiguating with Template

In Disambiguating with Typename [49, 169], we saw how it is sometimes necessary to tell the compiler explicitly that a nested name is a type name so that the compiler can perform a correct parse. The same situation arises with nested template names.

The canonical example is in the implementation of an STL allocator. If you’re not familiar with STL allocators, don’t worry, be happy. Previous familiarity with them is not necessary for following this discussion, though a good deal of patience might be.

An allocator is a class type that is used to customize memory management operations for STL containers. Allocators are typically implemented as class templates:

The class template AnAlloc contains the nested ...

Get C++ Common Knowledge: Essential Intermediate Programming 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.