struct B1{
int d;
void fb(){};
};
struct B2 : B1{
using B1::d;
using B1::fb;
int d; // why this gives error?
void fb(){} // and this does not?
};
int main(){}
Is it because, B1::fb() is treated as B1::fb(B1*) and B2::fb() treated as B2::fb(B2*)? That is, does the implicit parameter, help in distinguishing these?
$13.3.1/4-
For nonconversion functions introduced
by a using-declaration into a derived
class, the function is considered to
be a member of the derived class for
the purpose of defining the type of
the implicit object parameter.
The C++ standard (C++03 §7.3.3/12) explains:
In your example,
B2::fb()hides theB1::fb()introduced by the using declaration.As for why it is ill-formed to have both
using B1::d;andint d;in the definition ofB2, the C++ standard (C++03 §7.3.3/10) explains:So, it is ill-formed for the same reason that the following is ill-formed: it results in two objects with the same name in a single declarative region: