Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 577843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:11:49+00:00 2026-05-13T14:11:49+00:00

I am really confused about private inheritance and protected inheritance. 1) in protected inheritance,

  • 0

I am really confused about private inheritance and protected inheritance.

1) in protected inheritance, the public and protected members become protected members in the derived class. In the private inheritance, everything is private. However, the derived class can never access the private members of the base class, is that right? The derived class can access the public and protected members in both cases. Is that right?

2) I noticed that the private members of the base class will never be touched by the derived class. So why are the private members inherited?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T14:11:50+00:00Added an answer on May 13, 2026 at 2:11 pm

    You are correct on point #1. Specifying private, protected or public when inheriting from a base class does not change anything access-wise on the derived class itself. Those access specifiers tell the compiler how to treat the base-class members when instances of the derived class are used elsewhere, or if the derived class happens to be used as a base class for other classes.

    UPDATE: The following may help to illustrate the differences:

    class Base
    {
        private:   int base_pri;
        protected: int base_pro;
        public:    int base_pub;
    };
    

    For classes derived from base:

    class With_Private_Base :   private Base   { void memberFn(); };
    class With_Protected_Base : protected Base { void memberFn(); };
    class With_Public_Base :    public Base    { void memberFn(); };
    
    // this would be the same for all of the above 3 classes:
    void With_PXXX_Base::memberFn()
    {
        base_pri = 1; // error: `int Base::base_pri' is private
        base_pro = 1; // OK
        base_pub = 1; // OK
    }
    

    For classes derived from the 3 derived classes:

    class A : public With_Private_Base { void memberFn(); }
    void A::memberFn()
    {
        base_pri = 1; // error: `int Base::base_pri' is private
        base_pro = 1; // error: `int Base::base_pro' is protected
        base_pub = 1; // error: `int Base::base_pub' is inaccessible
    }
    
    class B : public With_Protected_Base { void memberFn(); }
    void B::memberFn()
    {
        base_pri = 1; // error: `int Base::base_pri' is private
        base_pro = 1; // OK
        base_pub = 1; // OK
    }
    
    class C : public With_Public_Base { void memberFn(); }
    void C::memberFn()
    {
        base_pri = 1; // error: `int Base::base_pri' is private
        base_pro = 1; // OK
        base_pub = 1; // OK
    }
    

    External access to the first three derived classes:

    void main()
    {
        With_Private_Base   pri_base;
        pri_base.base_pri = 1; // error: `int Base::base_pri' is private
        pri_base.base_pro = 1; // error: `int Base::base_pro' is protected
        pri_base.base_pub = 1; // error: `int Base::base_pub' is inaccessible
    
        With_Protected_Base pro_base;
        pro_base.base_pri = 1; // error: `int Base::base_pri' is private
        pro_base.base_pro = 1; // error: `int Base::base_pro' is protected
        pro_base.base_pub = 1; // error: `int Base::base_pub' is inaccessible
    
        With_Public_Base    pub_base;
        pub_base.base_pri = 1; // error: `int Base::base_pri' is private
        pub_base.base_pro = 1; // error: `int Base::base_pro' is protected
        pub_base.base_pub = 1; // OK
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.