According to https://www.ibm.com/docs/en/i/7.5?topic=only-name-hiding, the assignment x = 0 in the following code is not ambiguous, because the declaration B::x has hidden A::x.
struct A {
int x;
};
struct B: A {
int x;
};
struct C: A, B {
void f() { x = 0; }
};
int main() {
C i;
i.f();
}
Is this correct? It sounds counterintuitive to me, so I tried copying it to https://cpp.sh/ to compile it. It didn't compile successfully, due to ambiguity.
Your compiler is right. The article is wrong, supposed it actually describes standard c++ (see pps).
What they say about name hiding applies for example here:
If there were no
int x;inBthenxinf()would refer toA::x, but the member is hiding the member of same name from the base, hencexinfdoes refer toB::x. There is no ambiguity.This does however, not apply to multiple inheritance as in the example on the page:
It would actually be weird if the order of
struct C: A,Bvsstruct C: B,Awould determine the namelook up forx. Instead, unqualified name lookup for a member in a nutshell works like this:This is only a very simple view (just enough to understand the examples), for the details I refer you to https://en.cppreference.com/w/cpp/language/unqualified_lookup.
PS: THe article has more misleading information.
"redundant" is the wrong word here. A
Cobject has two distinctAsubobjects. Its just not possible to access either of them, because whatever way you'd use to access it cannot differentiate between theAinherited viaBand the one inherited directly.PPS: The reason for this discrepancy might be that you are looking at (quoted from here):
I never heard of a "ILE version of C++" before, though it appears to be a dialect.