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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access