Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can a parent members be called in Private Inheritance?
    primarykey
    data
    text
    <p>I am going through a book on Design Patterns by GoF - <a href="http://www.uml.org.cn/c++/pdf/DesignPatterns.pdf" rel="nofollow">online link</a>.</p> <p>In this book, in Adapter pattern, in Sample Code section, I have come across this particular code:</p> <pre><code>class TextView { public: TextView(); void GetOrigin(Coord&amp; x, Coord&amp; y) const; void GetExtent(Coord&amp; width, Coord&amp; height) const; virtual bool IsEmpty() const; }; </code></pre> <p>This class <code>TextView</code> is privately inherited by <code>TextShape</code> as below:</p> <pre><code> class TextShape : public Shape, private TextView { public: TextShape(); virtual void BoundingBox( Point&amp; bottomLeft, Point&amp; topRight ) const; virtual bool IsEmpty() const; virtual Manipulator* CreateManipulator() const; }; </code></pre> <p>Then in this <code>void TextShape::BoundingBox</code> function as below:</p> <pre><code> void TextShape::BoundingBox ( Point&amp; bottomLeft, Point&amp; 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); } </code></pre> <p>As one can see, the functions <code>GetExtent</code> &amp; <code>GetOrigin</code> is called TextShape, whereas, the class <code>TextView</code> containing these was inherited privately.</p> <p>My understanding is that, in private-inheritance, all the <code>parent class</code> members become inaccessible, so how is this (<code>void TextShape::BoundingBox()</code>) function trying to access it?</p> <p><strong>UPDATE:</strong></p> <p>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 :)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload