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 the basics of 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

Built with VitePress