Listing 2 illustrates an ambiguous case, where two superclasses use the same name.
Listing 2: | ambiguous |
In this case, the compiler catches the problem, and generates errors as follows:
ambiguous.cc: In function ’void test()’:
ambiguous.cc:25: error: request for member ’j’ is ambiguous ambiguous.cc:11: error: candidates are: int B::j ambiguous.cc:5: error: int A::j |
The error message is quite clear, and it points to the possible candidates. Note that the error is on line 25, and not in the definition of class C. In other words, class C does inherit both properties named j from A and B.
To fix this problem, replace line 25 with
myC.B::j = 0;
|
In other words, instead of saying “property j of myC”, we now say “property j inherited from class B of myC”.