Could someone please explain the following compiler error to me:
struct B
{
};
template <typename T>
struct A : private T
{
};
struct C : public A<B>
{
C(A<B>); // ERROR HERE
};
The error at the indicated line is:
test.cpp:2:1: error: 'struct B B::B' is inaccessible
test.cpp:12:7: error: within this context
What exactly is inaccessible, and why?
The problem is name shielding of struct B . Check it out:
You are making
A
private
ly inherit fromB
when you doA<B>
, and that means thatB::B
isprivate
so you can't construct aC
.Try
A< ::B>
orA<struct B>
.Inside of
C
, unqualified references toB
will pick up the so-called injected-class-name, it is brought in through the base classA
. SinceA
inherits privately fromB
, the injected-class-name follows suit and will also be private, hence be inaccessible toC
.Another day, another language quirk...