Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>One of the cases where I applied the "friend classes", is where one class is composed or referenced by other (objects) classes, and the composing objects, require access to the internals of the main class.</p> <pre><code>enum MyDBTableButtonBarButtonKind { GoFirst, GoPrior, GoNext, GoLast } class MyDBTableButtonBarButtonWidget; class MyDBTableButtonBarWidget { friend class MyDBTableButtonBarButtonWidget; // friend access method: protected: void GoFirst(); void GoPrior(); void GoNext(); void GoLast(); void DoAction(MyDBTableButtonBarButtonKind Kind); }; class MyDBTableButtonBarButtonWidget { private: MyDBTableButtonBarWidget* Toolbar; public: MyDBTableButtonBarButtonWidget(MyDBTableButtonBarWidget* AButtonBar) { this ButtonBar = AButtonBar; } MyDBTableButtonBarButtonKind Kind; public: virtual void Click() { Buttonbar-&gt;DoAction(this Kind); }; }; void MyDBTableButtonBarWidget::DoAction(MyDBTableButtonBarButtonKind Kind) { switch (Kind) { case MyDBTableButtonBarButtonKind::GoFirst: this.GoFirst(); break; case MyDBTableButtonBarButtonKind::GoLast: this.GoLast(); break; } } </code></pre> <p>In this example, there is a widget control that is a bar composed of buttons, the buttonbar is referenced to a D.B. table, and has several buttons for a specific action, like select the first record of the table, edit, move to the next.</p> <p>In order to do so, each button class has friend access to private &amp; protected methods, of the given control. As previous answer in this post, usually friend classes act a single class, decomposed in several smaller classes.</p> <p>It's not a finished example, its only a general idea.</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.
    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