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 6870643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:42:29+00:00 2026-05-27T03:42:29+00:00

Could someone explain what exactly private/protected inheritance in C++ is for, and what problem(s)

  • 0

Could someone explain what exactly private/protected inheritance in C++ is for, and what problem(s) it is intended to solve?

class Bar { };
class Foo : private Bar { };

I’ve already seen this question but I still don’t understand what it is, let alone when I should use it.

(Comparison to features in Java/C# or similar languages could also be helpful.)

  • 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-27T03:42:29+00:00Added an answer on May 27, 2026 at 3:42 am

    The private inheritance models “is-implemented-in-terms-of”. The meaning is similar to “has-a”. The differences are:

    1. With private inheritance you don’t need to write a wrapper (good for lazy programmers)

    2. “has-a” allows you better control, you can expose only a subset of the interface or change method names if you like.

    3. Private inheritance makes exception safety difficult, have a look at exceptional c++ for more information

    4. You really need private inheritance just when you want to use a protected members of your base class.

    5. Sometimes private inheritance is used in the mix-in class (Effective c++ memory management chapters)

    My personal preference is using “has-a” for general purpose, I use private inheritance just after I have rule out other options.

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

Sidebar

Related Questions

Could someone explain why this works in C#.NET 2.0: Nullable<DateTime> foo; if (true) foo
Could someone please explain, what exactly this O_LARGEFILE option does to support opening of
Could someone please explain what exactly recursion is (and how it works in Ruby,
Could someone explain what exactly a key object is for use in hashmap? There
Could someone please explain me what is exactly a gist feature vector of a
Could someone please explain what the difference is between these two examples? Class A
Could someone please explain the purpose of this option and what exactly it is
Could someone please explain, I do not exactly get the concept. What is a
Could someone explain to me in simple terms the easiest way to change the
Could someone explain? I understand the basic concepts behind them but I often see

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.