class B is nested insider class A but it does not declare the class B as its friend. However, the member function void B::print(A a) can access to the private member data int a, b of class A. The books introduce the nested class must be declared as friend then to access the private member data. Does this have been changed in c++ standard?
code:
#include <iostream>
using namespace std;
class A
{
int a , b;
public:
A():a(1),b(2){}
//class B;
//friend class B;
class B
{
public:
void print(A aa)
{
cout << "A.a = " << aa.a << ", A.b = " << aa.b <<endl; //aa.a and aa.b are private member data of class A
}
};
};
int main()
{
A a;
A::B b;
b.print(a);
}