Function Templates

  • Ray Lischner


You saw in Exploration 24 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 implementer 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 may be identical, differing only in the return type and parameter type. This Exploration introduces this style of programming, called generic programming.


Angle Bracket Function Argument Return Type Argument Type Head File 
These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.

Copyright information

© Ray Lischner 2013

Authors and Affiliations

  • Ray Lischner
    • 1
  1. 1.MDUS

Personalised recommendations