Templates allow these data structures to be more versatile. For example, a linked list implemeneted with templates allows for the same code to support a list of characters, integers, or doubles. An integer list can be easily implemented, as we have demonstrated in Lab 3. Some major modification of the integer list code will be needed to make it work as a character list.
Templates allow reuse of code regardless of types.
Templates allow you to prepare the compiler for a list of any data type, rather than creating a set of type-specific lists. The LinkedList program in Lab 3, only implements an integer class of linked list. If we use templates, we can make the LinkedList class not only take int as the data type, but also char , float , etc. This is possible with templates, because the type of the list becomes a parameter to the definition of the class. Use function templates to write generic functions that can be used with arbitrary types.