Item 49. Disambiguating with Typename

Even experienced C++ programmers are often put off by the rather complex syntax required to program with templates. Of all the syntactic gyrations one has to undertake, none is more initially confusing than the occasional need to help the compiler disambiguate a parse.

As an example, let’s look at a portion of an implementation of a simple, nonstandard container template.

image

It’s common practice for class templates to embed information about themselves as nested type names. This allows us to access information about the instantiated template through the appropriate nested name (see Embedded Type Information ...

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.