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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:08:09+00:00 2026-05-30T19:08:09+00:00

I am going through a book on Design Patterns by GoF – online link

  • 0

I am going through a book on Design Patterns by GoF – online link.

In this book, in Adapter pattern, in Sample Code section, I have come across this particular code:

class TextView {
     public:
         TextView();
         void GetOrigin(Coord& x, Coord& y) const;
         void GetExtent(Coord& width, Coord& height) const;
         virtual bool IsEmpty() const;
}; 

This class TextView is privately inherited by TextShape as below:

  class TextShape : public Shape, private TextView {
     public:
         TextShape();
              virtual void BoundingBox(
             Point& bottomLeft, Point& topRight
         ) const;
         virtual bool IsEmpty() const;
         virtual Manipulator* CreateManipulator() const;
  };

Then in this void TextShape::BoundingBox function as below:

   void TextShape::BoundingBox (
         Point& bottomLeft, Point& topRight
     ) const {
         Coord bottom, left, width, height;

         GetOrigin(bottom, left);  //How is this possible? these are privately inherited??
         GetExtent(width, height); // from textView class??
         bottomLeft = Point(bottom, left);
         topRight = Point(bottom + height, left + width);
     }

As one can see, the functions GetExtent & GetOrigin is called TextShape, whereas, the class TextView containing these was inherited privately.

My understanding is that, in private-inheritance, all the parent class members become inaccessible, so how is this (void TextShape::BoundingBox()) function trying to access it?

UPDATE:

Thanks all for answering, I had got into a wrong notion while reading about private inheritance. I felt, it would even prevent access to any of the members, whereas practically it changes the access-specifiers and not accessibility. Thanks you very much for clarifying 🙂

  • 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-30T19:08:10+00:00Added an answer on May 30, 2026 at 7:08 pm

    During private inheritance, the parent members become inaccessible for everyone else, not the class itself! The protected and public members of the parent class are still accessible in the derived class and friends thereof.

    Example:

    class Base
    {
        public: int publ;
        protected: int prot;
        private: int priv;
    };
    
    class Derived: private Base
    {
        friend void g();
        void f()
        {
             priv = 42; //error, priv is private
             prot = 42; //OK
             publ = 42; //OK 
        }
    };
    
    int main()
    {
        Derived d;
        d.priv = 42; //error
        d.prot = 42; //error
        d.publ = 42; //error
    }
    
    void g()
    {
        Derived d;
        d.priv = 42; //error
        d.prot = 42; //OK
        d.publ = 42; //OK
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please help me with this code - I am basically going through a book
While going through the book Scala for the Impatient , I came across this
I was going through Jeffrey Palermo's book and came across this syntax. private void
Hi I was going through the SCJP book about the innerclasses, and found this
I was just going through Design Patterns Questions on Stackoverflow and everyone mentioned about
I'm going through the book ANSI Common Lisp by Paul Graham, and there's this
I was going through some Java tutorials in a book and ran across code
I'm new to programming & i found this code when i was going through
Preface: This is not a homework question. I'm going through an algos book in
I was going through the Programming Interviews Exposed book. There's a code given for

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.