Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

What Are Templates?

Templates are C++’s way of writing generic code that can work on any data type (built-in and user-defined).

In essence, templates automate code generation. You write the function logic once, and the compiler generates the necessary versions for each data type you use.

Eventhough template itself needs a separate book to understand each and every aspect of it, here we will cover all the basic things about template.