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:
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 ...
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.