O'Reilly logo

SAMS Teach Yourself C++ in 10 Minutes SECOND EDITION by Jesse Liberty

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required