C++11 §11.2/5:
”
A member m
is accessible at the point R when named in class N
if
m
as a member of N
is public, or
m
as a member of N
is private, and R occurs in a member or friend of class N
, or
m
as a member of N
is protected, and R occurs in a member or friend of class N
,
or in a member or friend of a class P
derived
from N
, where m
as a member of P
is public, private, or protected, or
there exists a base class B
of N
that is accessible at R,
and m
is accessible at R when named in class B
.
For your constructor invocation
Base b2;
the 3rd point above applies. m
is the Base
constructor. N
, the naming class, is Base
. m
as a member of Base
is protected, and the declaration occurs in a member of class Derived
derived from Base
, but it's not the case that the Base
constructor as a member of Derived
is public, private or protected: it’s simply not a member of Derived
, constructors are not implicitly inherited.
I think the language “is public, private, or protected” is pretty awkward; I can only surmise that it’s the result of some evolution of this paragraph.
I have yet to find an explanation of how formally the protected Base
constructor is accessible in a member initializer list in Derived
, but then I just started looking at this for this question.
Update: I fail to find any language in the standard pertaining to access to constructors in an initializer list, and I fail to find any Defect Report about it. It’s quite possibly a defect.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…