Templates

Chapter
Part of the Undergraduate Topics in Computer Science book series (UTICS)

Abstract

If we want to write a function that returns the larger of two numbers, and we want this function to be used for both integer variables and double precision floating point variables, then we could write two functions: one for integer variables and the other for double precision floating point variables. Both of these functions would require only a few lines of code, and it would not be difficult to maintain both functions. For larger functions maintaining more than one function to do the same operations may be problematic. This may be avoided by the use of templates, a feature of the C++ language that allows very general code to be written. We begin this chapter by discussing templates and the flexibility that they permit. One library associated with C++ is the Standard Template Library (STL): we conclude this chapter by giving a brief survey of this library, and other functionality that has been introduced in recent C++ standards.

Copyright information

© Springer International Publishing AG, part of Springer Nature 2017

Authors and Affiliations

  1. 1.University of OxfordOxfordUK

Personalised recommendations