15.3 CLASS TEMPLATES

So far, we have studied function templates. There focus was on developing a single function. It used the parameters of type template. When we study class template, we will be defining a class. Focus will be on a class. It will have many data members and methods. This class will use a template type say T. The data members and methods will also use template type T. When using this class, only in the main program, we will define what we mean by T. For example, we may define template based class LIST as

     template <class T>      class LIST  {…}

We will declare object mylist as

    LIST <int> mylist;

This tells the computer that mylist is a LIST such that T is “int”.

The “class template” is also called a generic class or class ...

Get Object Oriented Programming with C++, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.