Friends

In some cases, it is convenient to let specific nonmember functions access the private members of a class while still preventing general access.
The friend mechanism allows a class to grant access to its nonpublic members to specified functions or classes. A friend declaration begins with the keyword friend. It may appear only within a class definition.

Example

The members of Window_Mgr can refer directly to the private members of Screen.

class Screen 
{
         // Window_Mgr members can access private parts of class Screen
         friend class Window_Mgr;
         // ...rest of the Screen class
     };
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.