C++ enables several functions of the same name to be defined, as long as they have different signatures. This is called function overloading. The C++ compiler selects the proper function to call by examining the number, types and order of the arguments in the call. Function overloading is used to create several functions of the same name that perform similar tasks, but on different data types. For example, many functions in the math library are overloaded for different numeric types—the C++ standard requires float
, double
and long double
overloaded versions of the math library functions discussed in Section 6.2.
Good Programming Practice 6.7
Overloading functions that perform closely related tasks can make programs more readable and understandable.