Skip to content

Template Basics

Templates are the core mechanism for generic programming in C++—write one piece of code, adapt it to multiple types. In this chapter, we start with function templates to see how the compiler automatically deduces type parameters for you. Then, we move on to class templates and understand how they differ from ordinary classes. Finally, we cover template specialization so you know what to do when you need special handling for a specific type. This is an introduction to templates; we will explore them in depth in the advanced volume.

Chapter Contents

v0.7.0-9-g940ec1b · 940ec1b · 2026-07-05