I am new to C++, and I don't know why this piece of code can pass.
#include<iostream>
using namespace std;
class A
{
public:
static void f(A a);
private:
int x;
};
void A::f(A a)
{
cout<<a.x<<endl;
}
int main(int argc, char const *argv[])
{
A a;
a.f(A());
return 0;
}
Here x is a private member of class A, so why can we access a.x in void A::f(A a)?
I hope to understand how this works.