Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Most languages that allow overloading of function definitions have this restrict

ID: 3723629 • Letter: M

Question

Most languages that allow overloading of function definitions have this restriction: they do not permit two definitions for the same function to differ only in the type of value returned. Ada must sometimes use the context of a function call to determine which overloaded definition to use. Consider the statement:= f(f(a,b), f(c, d)) in an Ada-like language.
Give an example of a set of types for the overloaded function f that makes this statement ambiguous, even when the types of a, b, c, d, and e are known.

Explanation / Answer

f(f(a,b), f(c, d))

Suppose the function definitions are:

int f(int a, int b)

{

    return (a + b);

}

float f(float c, float d)

{

    return (c + d);

}

int main()

{

    int a = 3, b = 4;

    float c = 1.2f, d = 3.8f, e;

    e = f(f(a, b), f(c, d));

    cout<<" Result: "<<e;

}

Call of overloaded 'f(int, float)' is ambiguous will occur.

Because f(a, b) will return integer and f(c, d) will return.

So, f(f(a, b), f(c, d)) will generate f(int, float) which is not available.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote