Explicit and implicit conversions from pointers or references to class types can cause ambiguities. Figure 9.11 shows the following:
D
.A
. Note that coercing the address of the object to type A*
does not always provide the compiler with enough information as to which subobject of type A
to select; in this case, two subobjects exist.
The conversion to type A*
(pointer to A
) is ambiguous because there is no way to discern which subobject of type A
is the correct one. Note that you can avoid the ambiguity by explicitly specifying which subobject you mean to use, as follows:
(A *)(B *)&d // Use B subobject.
(A *)(C *)&d // Use C subobject.
Figure 9.11 Ambiguous Conversion of Pointers to Base Classes