Chapter 3
Ada Language Reference
©
National Instruments Corporation
3-37
Example 3-6
Example Code Causing Ambiguous Selection of Overloaded Operators
function "*" (left:SB0; right:SB1) return SL0;
function "*" (left:SB0; right:SB1) return SS0;
function "*" (left:SL0; right:SL0) return SL0;
function "*" (left:SS0; right:SL0) return SL0;
function TO_SLO (left:SL0) return SL0;
V1 : SB0; V2 : SB1: VL:SL0;
begin
VL := V1 * V2 * VL --ambiguous
VL := TO_SL0(V1 * V2) * VL; --unambiguous expression
end;
The first assignment is ambiguous because there is more than one choice of
the overloaded operator function that would satisfy the first multiplication
subexpression. The second assignment is not ambiguous because the
TO_SLO
function is unary and not overloaded. Therefore, the unary
function is forcing the
V1*V2
subexpression to return a SL0 result. Thus,
there is only one operator that satisfies the second example.