Assignment Answers

Chapter 1, Introduction to Templates

Question 1

Why do we need templates? What advantages do they provide?

Answer

There are several benefits to using templates: they help us avoid writing repetitive code, they foster the creation of generic libraries, and they can help us write less and better code.

Question 2

How do you call a function that is a template? What about a class that is a template?

Answer

A function that is a template is called a function template. Similarly, a class that is a template is called a class template.

Question 3

How many kinds of template parameters exist and what are they?

Answer

There are three kinds of template parameters: type template parameters, non-type template parameters, and template template ...

Get Template Metaprogramming with C++ 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.