GoFによるデザインパターンに関する本を読んでいます-オンラインリンク。
この本のアダプタパターンのサンプルコードセクションで、私はこの特定のコードに出くわしました。
class TextView {
public:
TextView();
void GetOrigin(Coord& x, Coord& y) const;
void GetExtent(Coord& width, Coord& height) const;
virtual bool IsEmpty() const;
};
このクラスTextView
は、以下のようにプライベートに継承さTextShape
れます。
class TextShape : public Shape, private TextView {
public:
TextShape();
virtual void BoundingBox(
Point& bottomLeft, Point& topRight
) const;
virtual bool IsEmpty() const;
virtual Manipulator* CreateManipulator() const;
};
次に、このvoid TextShape::BoundingBox
関数で次のようになります。
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);
}
ご覧のとおり、関数GetExtent
&GetOrigin
はTextShapeと呼ばれますが、TextView
これらを含むクラスはプライベートに継承されています。
私の理解では、私的継承では、すべてのparent class
メンバーがアクセスできなくなります。では、この(void TextShape::BoundingBox()
)関数はどのようにアクセスしようとしているのでしょうか。
アップデート:
答えてくれてありがとう、私は私的継承について読んでいるときに間違った考えに陥っていました。私は、それはどのメンバーにもアクセスを妨げるだろうと感じましたが、実際にはアクセス指定子を変更し、アクセシビリティを変更しません。明確にしていただきありがとうございます:)