3.4 FUNCTION OVERLOADING
Before C++, functions were identified by their name. To avoid ambiguity, no two functions were allowed to have same name. In C++, we can have two or more functions having same name. This is called function overloading. To resolve ambiguity, the number of parameters and their respective data types in the parameter list of each function must be different. The number of parameters and their respective data types is called the signature of the function3. So even if the names of the function are the same, it is by their signatures the functions are uniquely identified.
Consider a case that we have to define function add for adding integers as well as real numbers. We can write two different functions as follows:
int add(int ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access