alias constant in the inherited class

I have a base class defining a constant and the child class can use it using alias. The construct is as below

class Base
{
protected:
    static const int A_ = 1;
};

class Foo : public Base
{
private:
    using Base::A_;
};

However, when I define a subclass of Foo as

class Go : public Foo
{
private:
    using Base::A_;
};

the compiler emits the error: error: ‘const int Base::A_’ is private within this context. I do not get it since Base::A_ is protected. What did the compiler see in this case and what can be the solution to use Base::A_ in Go ?

>Solution :

I do not get it since Base::A_ is protected.

Go inherits from Foo not from Base. A_ is private in Foo not protected.

If you want to have access to A_ in classes derived from Foo then A_ should be public or protected in Foo.

Leave a Reply