Templating

Objectives

  • Discuss templating in general terms
  • Implement a templated linked list

Templating

We will implement a templated version of a linked list class. This will allow us to store any data type in the linked list while only writing the code for a linked list one time. First, we will develop a linked list class. Then we will create a templated version of that class.

  • An example of function templating is available as template1.cpp.
  • Linked list demonstration
  • Templating linked lists
    • MyObj.h: simple class used for filling tlist
    • tlist.h: implementation of templated linked list class using dynamic memory allocation
    • TestTList.cpp: test driver for tlist.h
    • gll.h: implementation of templated linked list class using reference variables
    • testgll.cpp: test driver for gll.h