g++
is denying me access to a type, just because it happens to be a private grand-father. Does this make sense?
struct A {};
struct B : private A {};
struct C : B {
void foo(A const& a) {}
};
Compiling this yields:
1:10: error: ‘struct A A::A’ is inaccessible
6:12: error: within this context
My point is: I never wanted to access A
as an ancestor. In fact, if A
is a private ancestor of B
, shouldn't this be completely invisible to anybody but B
(i.e. C
)?
Of course, I could use protected
inheritance but in my case it doesn't really make sense.
This is due to the injected class name from A
hiding the global A
inside C
. Although A
is visible, it is not accessible (since it is imported as private), hence the error. You can access A
by looking it up in the global namespace:
void foo(::A const& a) {}
if you declare it as follows it works
struct A {};
struct B : private A {};
struct C : B {
void foo(::A const& a) {}
};
The error your seeing is do to name resolution not access. The ::A says look at the global namespace not my inherited nested class types. Also remember that private inheritance is just saying B has an A and IMOHO is a stupid language feature that should be avoided.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With