August 2001
Beginner
482 pages
10h 52m
English
You declare a parameterized List object (a template for a list) by writing
1: template <class T> // declare the template and the parameter
2: class List // the class being parameterized
3: {
4: public:
5: List();
6: // full class declaration here
7 :};
The keyword template is used at the beginning of every declaration and definition of a template class. The parameters of the template are after the keyword template; they are the items that will change with each instance. For example, in the list template shown in the previous code snippet, the type of the objects stored in the list will change. One instance might store a list of Integers, whereas another might store a list of Animals.
In this example, the keyword class is ...
Read now
Unlock full access