friend specifier
Aus cppreference.com
![]() |
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
This section is incomplete Reason: needs cleanup |
[Bearbeiten] Beschreibung
Der Freund Schlüsselwort wird verwendet, um den Zugriff auf die Mitglieder von außerhalb der Klasse zu gewähren. Angenommen, Ihre Klasse private oder protected Mitglieder. Sie können diese Elemente nur aus der gleichen Klasse oder abgeleiteten Klassen jeweils zugreifen. Durch die Verwendung der Freund Schlüsselwort, das Sie gewähren Zugang zu den private und geschützte Member der Klasse der friend-Funktion oder einen Freund Klasse. Einige der häufigsten Anwendungen von Freund sind die operator >> und operator << Funktionen und die Swap-Funktion .
Original:
The friend keyword is used to grant access to class members from outside of the class. For example, suppose your class has private or protected members. You can access these members only from the same class or derived classes respectively. By using the friend keyword you grant access to the private and protected members of your class to the friend function or a friend class. Some of the more common uses of friend are the operator>> and operator<< functions and the swap function.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[Bearbeiten] Beispiel für die Verwendung
friend ostream& operator<<(ostream& out, const T& o); friend istream& operator>>(istream& in, T& o); friend swap(T& left, T& right);