samedi 30 mai 2020

Why can't an inherited protected ctor be made public?

class A
{
protected:
    A(int) {}
    void f(int) {}

public:
    A() {}
};

class B : public A
{
public:
    using A::A;
    using A::f;
};

int main()
{
    B().f(1); // ok
    B(1); // error: 'A::A(int)' is protected within this context
}

Why can't an inherited protected ctor be made public, while an inherited protected member function can?

Aucun commentaire:

Enregistrer un commentaire