O'Reilly logo

C++ Common Knowledge: Essential Intermediate Programming by Stephen C. Dewhurst

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Item 57. Template Argument Deduction

Class templates must be specialized explicitly. For example, if we want to specialize the Heap container discussed in Class Template Explicit Specialization [46, 155], we have to provide a type name argument to the template:

Heap<int> aHeap;Heap<const char *> anotherHeap;

Function templates may also be specialized explicitly. Suppose we have a function template that performs a restricted old-style cast:

image

We may specialize the template explicitly when we call it, just as we must specialize a class template:

int a = cast<int,double>(12.3);

However, it’s typical and more convenient to let the compiler deduce ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required