10.4. Specializing Template Classes

Template class specialization is similar to specializing template functions (page 400). Once you define a template class for a generic type, specialized versions for specific types are possible. There are two reasons why you specialize template classes.

  1. A template class generates compilation errors for a specific type or does not work properly, and a correct version for that type is necessary.

  2. A template class member function executes slowly for a specific type, and you need to improve performance with a different type-specific function.

There are a few rules you need to know when specializing template classes. First, the class definition for the specialized class must appear after the generic template class ...

Get Navigating C++ and Object-Oriented Design 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.