struct A { int i; };
struct B { int i; };
struct C: A, B {
using A::i;
void f() {
i = 0;
}
};
This compiles happily. As far as I know, it is because using A::i; hides B::i.
struct A { int i; };
struct B: A {};
struct C: A {};
struct D: B, C {
using B::i;
void f() {
i = 0;
}
};
But this does not compile, saying error: 'A' is an ambiguous base of 'D'. I don't understand what's the difference between those two. Why using B::i; does not hide C::i here?
Edit: I'm not trying to make something with that design. I know I should use virtual inheritance most of the case. I'm just wondering about the syntax of c++.
Edit: I'm still confusing with answers (which is now deleted) such as "B::i is same as A::i in second example". What I'm wondering is why is that. Where can I find basic syntax rules that makes B::i and A::i same? I have "The C++ Programming Language" of Bjarne Stroustroup, but that book is simply unreadable to me as a non native English user. If you also have the book, I'd appreciate it if you tell me the section of the book describing this problem.