Search

14.6 — Partial template specialization

In the lesson on expression parameters and template specialization, you learned how expression parameters could be used to parametrize template classes.

Let’s take another look at the Buffer class we used in the previous example:

Now, let’s say we wanted to write a function to print out a buffer as a string. Although we . . . → Read More: 14.6 — Partial template specialization

14.5 — Class template specialization

In the previous lesson on template specialization, we saw how it was possible to specialize member functions of a template class in order to provide different functionality for specific data types. As it turns out, it is not only possible to specialize member functions of a template class, it is also possible to specialize an . . . → Read More: 14.5 — Class template specialization

14.4 — Expression parameters and template specialization

In previous lessons, you’ve learned how to use template type parameters to create functions and classes that are type independent. However, template type parameters are not the only type of template parameters available. Template classes (not template functions) can make use of another kind of template parameter known as an expression parameter.

Expression parameters

A . . . → Read More: 14.4 — Expression parameters and template specialization

14.3 — Template classes

In the previous two lessons, you learn how function templates and function template instances could be used to generalize functions to work with many different data types. While this is a great start down the road to generalized programming, it doesn’t solve all of our problems. Let’s take a look at an example of one . . . → Read More: 14.3 — Template classes

14.2 — Overloading operators to make function templates work with class types

In lesson %Failed lesson reference, id 11255%, we discussed how the compiler will use function templates to instantiate functions, which are then compiled. We also noted that these functions may not compile, if the code in the function template tries to perform some operation that the actual type doesn’t support (such as adding integer value . . . → Read More: 14.2 — Overloading operators to make function templates work with class types

8.13 — Function templates

Let’s say you wanted to write a function to calculate the maximum of two numbers. You might do so like this:

While the caller can pass different values into the function, the type of the parameters is fixed, so the caller can only pass in int values. That means this function really only works . . . → Read More: 8.13 — Function templates