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

  • SEARCH
  • Home
  • 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 9079809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:55:24+00:00 2026-06-16T19:55:24+00:00

Possible Duplicate: What are access specifiers? Should I inherit with private, protected or public?

  • 0

Possible Duplicate:
What are access specifiers? Should I inherit with private, protected or public?

How can I create a derived class in C++ which preserves the properties and methods’ access specifier like this:

class Base
{
private:
    void base_private();

protected:
    void base_protected();

public:
    void base_public();
};

class A: [what type is appropriate here?] Base
{
public:
    void test() {
        base_protected(); // Ok
    }
};

class B: [what type is appropriate here?] A
{
public:
    void test() {
        base_protected(); // Ok
    }
};

int main()
{
    A a;
    B b;

    a.base_public();        // Ok
    a.base_protected();     // Not Ok
    b.base_protected();     // Not Ok
    b.test();               // Ok

    return 0;
}

I mean base_protected() method is still protected in derived classes but base_public() is public.

  • 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-06-16T19:55:25+00:00Added an answer on June 16, 2026 at 7:55 pm

    Lets consider the availability of members of Base:

    • base_private is not available to clients but available to Base itself
    • base_protected is not available to clients but available to Base itself
    • base_public is available to both clients and Base

    Now, if you have class A : public Base (public inheritance), the availability of the members of Base will be:

    • base_private is not available to clients and not available to A itself
    • base_protected is not available to clients but available to A itself
    • base_public is available to both clients and A

    Now, what you’re asking about is how to keep the same client interface for both classes, Base and A. If you look at the availability of the members for clients in the lists above, you will see that it is precisely the same for Base and A: base_private is not available; base_protected is not available; and base_public is available.

    The only thing that has changed between Base and A is that A cannot access the members that are private to Base. That’s the whole point of the protected access control – it gives derived classes access to their base classes members without making them available to clients.

    So public inheritance is what you need.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: What are access specifiers? Should I inherit with private, protected or public?
Possible Duplicate: What are access specifiers? Should I inherit with private, protected or public?
Possible Duplicate: Can inner classes access private variables? Inner class accessing outer class I
Possible Duplicate: Should you access a variable within the same class via a Property?
Possible Duplicate: Cannot access private member in singleton class destructor I'm implementing a singleton
Possible Duplicate: Can I create an automatic property (no private member) with get and
Possible Duplicate: How can I access local scope dynamically in javascript? Hi all. We
Possible Duplicate: C++ delete - It deletes my objects but I can still access
Possible Duplicate: C++ Inherited template classes don't have access to the base class I'm
Possible Duplicate: Can javascript access iframe elements from the parent page? I have an

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.