在SO周围搜索之后,有一个问题告诉我,内联好友函数的词法范围是其定义的类,这意味着它可以访问typedef类中的,而无需对其进行限定。但是我想知道这样的功能的实际范围是什么?GCC至少拒绝了我所有的调用尝试。能否通过非ADL的方式调用示例中的函数(由于没有参数,在这里是不可能的)?
感谢标准报价,因为我目前无法访问它的副本。
以下代码
namespace foo{
struct bar{
friend void baz(){}
void call_friend();
};
}
int main(){
foo::baz(); // can't access through enclosing scope of the class
foo::bar::baz(); // can't access through class scope
}
namespace foo{
void bar::call_friend(){
baz(); // can't access through member function
}
}
导致以下错误:
prog.cpp: In function ‘int main()’:
prog.cpp:9: error: ‘baz’ is not a member of ‘foo’
prog.cpp:10: error: ‘baz’ is not a member of ‘foo::bar’
prog.cpp: In member function ‘void foo::bar::call_friend()’:
prog.cpp:15: error: ‘baz’ was not declared in this scope
明月笑刀无情
qq_笑_17
相关分类