Why is the global function void showA(A& x) able to access private members of class A? I know that the function with similar method signature is declared as a friend of class A but the global showA() isn't the same as the function showA(A&) declared inside class A.
#include <iostream>
class A {
int a;
public:
A() { a = 0; }
friend void showA(A&);
};
void showA(A& x) function
{
std::cout << "A::a=" << x.a;
}
int main()
{
A a;
showA(a);
return 0;
}