6.4. Overloaded Functions

Image

Functions that have the same name but different parameter lists and that appear in the same scope are overloaded. For example, in § 6.2.4 (p. 214) we defined several functions named print:

void print(const char *cp);void print(const int *beg, const int *end);void print(const int ia[], size_t size);

These functions perform the same general action but apply to different parameter types. When we call these functions, the compiler can deduce which function we want based on the argument type we pass:

int j[2] = {0,1};print("Hello World");        // calls print(const char*)print(j, end(j) - begin(j)); // calls print(const ...

Get C++ Primer, Fifth 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.