Abstract
You saw in Exploration 22 that the magic of overloading lets C++ implement an improved interface to the absolute value function. Instead, of three different names (abs, labs, and fabs), C++ has a single name for all three functions. Overloading helps the programmer who needs to call the abs function, but it doesn’t help the implementor much, who still has to write three separate functions that all look and act the same. Wouldn’t it be nice if the library author could write the abs function once instead of three times? After all, the three implementations are identical, differing only in the return type and parameter type. This Exploration introduces this style of programming, called generic programming.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Preview
Unable to display preview. Download preview PDF.
Rights and permissions
Copyright information
© 2009 Ray Lischner
About this chapter
Cite this chapter
(2009). Function templates. In: Exploring C++. Apress. https://doi.org/10.1007/978-1-4302-0352-0_46
Download citation
DOI: https://doi.org/10.1007/978-1-4302-0352-0_46
Publisher Name: Apress
Print ISBN: 978-1-59059-749-1
Online ISBN: 978-1-4302-0352-0
eBook Packages: Professional and Applied ComputingProfessional and Applied Computing (R0)Apress Access Books