Chapter 5:Semantic Analysis

Overloaded functions and operators .

. Suppose only possible type for 2, 3 and 5 is integer and Z is a complex variable

- then 3*5 is either integer or complex depending upon the context

- in 2*(3*5)

3*5 is integer because 2 is integer

- in Z*(3*5)

3*5 is complex because Z is complex

Here you can see that the compiler decides version of an overloaded operator to use from the types of the parameters passed to it. In 2*(3*5), 3*5 is integer because 2 is integer. And in Z*(3*5), 3*5 is complex because Z is complex. Hence the resolution depends on the context in which the operator is being used.