Assuming the following layout:
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;
};
Should I be able to specify Derived
's constructor as public here? VC++ gives the following error:
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'
i.e. it's ignoring the access modifier above the inherited constructor.
Is this a limitation of the feature? It doesn't make any sense for the Base
class to have a public constructor, as it can never be instantiated directly (due to the pure virtual method).
question from:
https://stackoverflow.com/questions/21015909/c11-inheriting-constructors-and-access-modifiers 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…