在课内定义的友元函数的范围是什么?

6
几天前我提出了一个关于课堂内定义友元函数范围的问题(Which scope does an in-class-defined friend function belong to?),并且我知道该函数在封闭命名空间的范围内,但在类外显式声明之前不可搜索(ADL是一个例外)。
今天我在C++标准中找到了一些相关的说明(第11.3节):

A function can be defined in a friend declaration of a class if and only if the class is a non-local class (9.8), the function name is unqualified, and the function has namespace scope. [ Example:

class M {  
    friend void f() { } // definition of global f, a friend of M,  
                        // not the definition of a member function  
};  
—end example ]

Such a function is implicitly inline. A friend function defined in a class is in the (lexical) scope of the class in which it is defined. A friend function defined outside the class is not (3.4.1).

我们可以看到这里有两个与作用域相关的语句:"具有命名空间作用域""在定义它的类的 (词法) 作用域中"。我感到困惑。如果前者与我先前的问题有关 (一个在类内定义的友元函数属于哪个作用域?),那么后者代表什么?

据我所知,这是关于友元函数内部名称查找的问题。实时示例 - dyp
1个回答

1

"命名空间范围函数"是指属于命名空间成员的函数(即这里的"范围"表示函数的"主范围")。

后面的陈述链接到3.4.1,其含义为

在授予友元的类内联定义的友元函数(11.3)的定义中使用的名称的名称查找应按照成员函数定义中描述的方式进行。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接