The following code doesn't compile:
class C
{
private:
int m_x;
protected:
C(int t_x) : m_x(t_x) { }
};
class D : public C
{
public:
using C::C;
};
int main(int argc, char **argv)
{
D o(0);
}
The compiler's objection is that the constructor for C is declared protected
, meaning that I can't access it from main
. In other words, it seems like the using
declaration drags the original visibility of the identifier with it, despite the fact that it lives in the public
block.
Two questions:
- Why does this happen? (Both in terms of the rules for how this works, and the rationale for making those rules).
- Is there any way I can get around this without explicitly writing a constructor for
D
?