关于c ++:C ++ 11继承构造函数和访问修饰符

C++11 inheriting constructors and access modifiers

假设如下布局:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class Base
{
protected:
    Base(P1 p1, P2 p2, P3 p3);

public:
    virtual void SomeMethod() = 0;
}

class Derived : public Base
{
public:
    using Base::Base;

public:
    virtual void SomeMethod() override;
};

我可以在这里指定Derived的构造函数为公共的吗?VC++给出以下错误:

cannot access protected member declared in class 'Derived'
compiler has generated 'Derived::Derived' here [points to the using Base::Base
line]
see declaration of 'Derived'

也就是说,它忽略了继承构造函数上方的访问修饰符。

这是功能的限制吗?Base类有一个公共构造函数是没有意义的,因为它永远不能直接实例化(由于是纯虚拟方法)。


根据12.9/4,"继承建设者",在说using X::X时,

A constructor so declared has the same access as the corresponding constructor in X.

所以继承的构造函数也是protected