Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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 ?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading