Declaring and Using Templates
You've seen a template in use before—std::vector<aRequest> myTape; in aTape, from Lesson 20, “The Rest of the Calculator as Classes.” This member variable declaration created an instance of vector that would only accept aRequest objects.
It can help to think of such a template as a form that will generate code for a class when you “fill in the blanks.”
Templates usually have only one or at most a few such “blanks,” which are called type parameters. A value supplied for the type parameter is used to replace that type parameter wherever it is mentioned in the template. In std::vector<aRequest>, aRequest is the value supplied for the type parameter of the vector template.
The format for coding a template can seem complex ...
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