How is unqualified name lookup being performed for names using within the friend's function body? Let's consider the following code:
#include <iostream>
void foo();
class A
{
friend void foo(){ std::cout << a << std::endl; }
static int a;
};
int A::a = 10;
int main(){ foo(); }
The Standard states in the N4296::7.3.1.2/3 [namespace.memdef]
:
If a friend declaration in a non-local class first declares a class, function, class template or function template the friend is a member of the innermost enclosing namespace.
So, I expected unqualified name lookup didn't find A::a
, but it did. I deliberately put the A::a
declaration after the friend's function definition in hope it wouldn't be found. What's the actual rule for the friend's unqualified name lookup?
A
while still be placed in the direct parent's scope. I've never considered this before; interesting find. – Qix - MONICA WAS MISTREATEDfriend
declaration and thestatic
member variable. I don't know why you think they are related. – R Sahu