EXPLORATION 48

image

Function Templates

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 ...

Get Exploring C++ 11, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.