1.

Discuss how the best match is found when a call to an overloaded function is encountered? Give example(s) to support your answer.

Answer»

In order to find the best possible match, the compiler follows the following steps: 1. Search for an exact match is performed. If an exact match is found, the function is invoked. For example, 2. If an exact match is not found, a match trough promotion is searched for. Promotion means conversion of integer types char, short, enumeration and int into int or unsigned int and conversion of float into double. 3. If first two steps fail then a match through application of C++ standard conversion rules is searched for. 4. If all the above mentioned steps fail, a match through application of user-defined conversions and built-in conversion is searched for.

For example,

void afunc(int);

void afunc(char);

void afunc(double);

afunc(471); //match through standard conversion. Matches afunc(int)



Discussion

No Comment Found

Related InterviewSolutions