class A {
friend void f() {}
};
// void f() {} // compile error: redifinition of 'void f()'
int main() {
f(); // compile error: 'f' is not declared in this scope
}
Run Code Online (Sandbox Code Playgroud)
正如您在上面的示例中所看到的,如果f在A封闭的命名空间作用域中调用,则编译器无法找到f,这使我的想法f不在此范围内.但是当添加具有相同签名的函数的无法定义时,编译器会发出函数重定义的错误,这给出了与f此范围内实际相反的想法.
所以,我很困惑一个类内定义的朋友函数属于哪个范围.
c++ ×1