From the course: C++ Templates and the STL

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Template specialization

Template specialization - C++ Tutorial

From the course: C++ Templates and the STL

Template specialization

- [Lecturer] When you invoke a template with a specific type the compiler creates a specialization for the template with that specific type. Let's take a look at how this works, here I have a working copy of template function .CPP from chapter one of the exercise files. When I call the template function on line sixteen the compiler creates a specialization, this happens at compile time. The specialization is effectively a copy of the function, specifically for a given set of types. The specialization is invisible to the programmer, this happens at compile time entirely behind the scenes. So in the case of our example, it's as if a function were created like this with Int Maxof const Int A, and const Int & B return and the rest of this is just exactly like that. (typing) So if I were to run this function several times once with type say short Int and once with type long Int, It would create three separate specializations of this function one with type short Int and one with type long…

Contents