friend specifier
来自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. |
| 本节是不完整的 原因: needs cleanup |
[编辑] 说明
Friend关键字用于授予访问类成员以外的类。例如,假设你的类有私有或受保护的成员。您可以访问这些成员只能从同一类或派生类。通过使用关键字的朋友,您授予访问您的类的友元函数或友元类的private和protected成员。的朋友的一些比较常见的用途是经营者“和运算符<<和交换功能.
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.
[编辑] 例如使用
friend ostream& operator<<(ostream& out, const T& o); friend istream& operator>>(istream& in, T& o); friend swap(T& left, T& right);

