According to the standard:
A friend function defined in a class is in the (lexical) scope of the class in which it is defined.
Then why the heck doesn't this work (several versions of GCC tested)?
#include <iostream>
using namespace std;
class A
{
friend void function() { cout << "text" << endl; };
};
// void function();
int main()
{
function();
return 0;
}
Uncommenting the declaration of course solves the problem.
Edit (gcc output):
(xterm) $ g++ -ansi -pedantic -Wall -Wextra test.cpp
test.cpp: In function ‘int main()’:
test.cpp:13:11: error: ‘function’ was not declared in this scope