需要帮助理解与朋友声明有关的段落
Need help understanding a paragraph pertaining to friend declaration
但是,您可以在友元声明中定义函数类必须是非本地类、函数,函数名称必须是非限定的,并且函数具有命名空间作用域下面的例子说明了这一点:
class A { void g(); };
void z() {
class B { // friend void f() { }; };
}
class C { // friend void A::g() { }
friend void h() { }
};
虽然我理解The class must be a non-local class
的意思,但在那个逗号之后,我就想不起来了,或者那个单独用逗号包围的虚词是打字错误?。我的意思是整个段落逐字逐句的意思。感谢
p.S以上段落是从ibm C++参考资料中窃取的->https://www-01.ibm.com/support/knowledgecenter/ssw_ibm_i_72/rzarg/cplr042.htm
这是C++14标准中的措辞:
[class.friend]/6函数可以在类的友元声明中定义,当且仅当该类是非局部类(9.8),函数名称不合格,并且函数具有命名空间作用域。示例:
class M { friend void f() { } // definition of global f, a friend of M, // not the definition of a member function };
--结束示例]
相关文章:
- .cpp和.h文件中的模板专用化声明
- 未在作用域中声明unordered_map
- C++避免重复声明的语法是什么
- 如何确保C++函数在定义之前声明(如override关键字)
- 错误:未在此范围内声明'reverse'
- 奇怪的(对我来说)返回声明 - 在谷歌上找不到任何关于它的信息
- 为什么在定义函数之前先声明它
- 如何声明特征矩阵,然后通过嵌套循环初始化它
- #ifdef和未声明的标识符
- 没有显式声明的int[]中的foreach
- 在基于范围的for循环中使用结构化绑定声明
- 在将变量声明为引用时,堆在释放后使用
- C++:无法访问声明的受保护成员
- 为什么我不能在一个类的不同行中声明和定义成员变量?
- 我不明白为什么我声明一个空的内部结构并将其传递给构造函数
- 使用cmake从源代码构建MySQL连接器/C++失败(与以前的声明冲突)
- 在函数内部的声明中初始化数组,并在外部使用它
- Visual Studio中的函数声明和函数定义问题
- c++类声明时,相同的例程,不同的成员变量类型
- 需要帮助理解与朋友声明有关的段落