C++ allows us to use the power of templates, just as we saw used in the standard vector, when we build our own classes and our own functions. Let's see how this works. A template variable is declared by using a special syntax before the beginning of a class or the beginning of a function. Looking at the beginning of a class here, before the definition of the class, we have template with an open angle bracket and typename T. The only thing that's going to differ in the syntax is the T, this is the variable name for a template. So, here in template typename T, we see that in our class list, we can have things with the type T. When we initiate this list class, we can have a list of integers or a list of strings or lists of uiuc cubes, it can be anything because the template type can take on another type, when the data structure is initialized. Likewise, we can also have template functions, here we see the exact same syntax template typename T, and inside the function itself we can use T as a type. Here is T a and T b and this function this int max simply looks at a and b, compares them and returns for the largest one, it returns the maximum of those two variables. Let's see how this actually gets instantiated when we run this code and compile this code. Templated variables are actually checked at compile time, which allows for errors to be caught before we even run our program. Consider our max function which we saw earlier, and when we run this max function we might call max a four and seven, when we call max a four and seven, we're asking the program to find the maximum of four and seven. Because these variables are both integers, it's going to instantiate a templated version of the max function with integers. So, it's going to be read as an int a and int b are both being compared from the max function. Since we have the if statement that compares whether or not a is greater than b, we're going to check if the integer four is greater than integer seven, since it's not we're going to go ahead and return b. On the other side of the world, we can think about uiuc cubes. So, instead of having a primitive type we have a user-defined type and in this user-defined type we're now comparing two cubes. When we compare a greater than b, we're comparing whether a cube of length three is greater than the cube of length six, and this results to an error because we have not programmed the ability for us to find out if one cube is greater than another cube, we haven't overloaded that operator, we haven't defined how a greater than sign might work, and because of that we cannot compare two cubes and when we try and compile this code we're going to find that there's going to be an error. Let's actually see this as an example, looking at the main program for the cpp templates video, we have our max function you saw earlier at the very top of our program and inside main we're going to call the max function several different times. On line 22, we compare max of three and five, we expect this to output the number five, then we compare the max of a and d. Notice the first was a comparison of integers, the second one's a comparison of characters between a and d, d is the largest. Next thing is we're going to compare the max of "Hello" and "World" this is a comparison of two strings. "World" is the larger string, so we expect "World" to be outputted. Then finally, the last line is we're going to compare two cubes. We're going to find the max of cube three and the max of cube six, we argued there is no idea of how to do a greater than operation between two cubes, so expect this code to not compile. When we remove this one line of code, when we remove line 25, we're going to see this code should compile and print out five d and "World". Let's go to the console and see if this works out. Here the console moving into this cpp-templates directory, I'm going to run make, and we get an error. So, we see invalid operand for binary expression uiuc cube to uiuc cube, and this is the a is greater than b. So, for a is greater than b we don't know how to do that for uiuc cube and we can in fax c where this specifically called in the next error message, note an instantiation of the template of function template specified 'maxuiuccube' request here, so when we did the max of the two cubes, we weren't able to create the template type because we can't compare a being greater than b. Let's go ahead and edit this code and remove this line 25 so that we can see the rest of this code work, editing main.cpp, commenting out line 25, saving the file, next thing running make, and now running./main since make ended up compiling this successfully, and we see the max of three and five is indeed five, the max of a and d is d, and the max of "Hello", "World" is World. So now, you've seen how we can create a templated type inside of our own code, and we're going to make use of this as we build more and more complicated data structures. Before then we want to talk a little bit more about the C++ language. So, I'll see you next time, when we talk about inheritance. I'll see you then.