Consider the following code:
#include <stdio.h>
class A
{
friend void foo(){ printf("%d\n",_a); }
public:
A(int);
private:
static const int _a=5;
};
class B
{
friend void foo(){ printf("%d\n",_a); }
private:
static const int _a=6;
};
int main()
{
foo();
}
After compiling I've the following errors:
an_test.cpp:14:14: error: redefinition of ‘void foo()’
an_test.cpp:5:14: error: ‘void foo()’ previously defined here
an_test.cpp: In function ‘int main()’:
an_test.cpp:21:6: error: ‘foo’ was not declared in this scope
make: *** [an_test.o] Error 1
I think that functions defined with friend specifier are external linkage. So why an_test.cpp:21:6: error: ‘foo’ was not declared in this scope?