Template Definition
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 ...
Get Sams Teach Yourself C++ in 24 Hours, Third 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.