Compiling this snippet with g++ i haven’t access to members...
Compiler says ....
i=23;//error: ‘i’ was not declared in this scope
a::i=23;//error: invalid use of non-static data member ‘a::i’
seta();//error: ‘seta’ was not declared in this scope
class B ;
private: int ia = 0 ;
friend B ; // B is a friend of A
void set( A& a2 )
ib = 123 ;
a.ia = 4567 ; // friend: can access private member of A
a2.ia += a.ia ; // friend: can access private member of A
A a ;
int ib = 0 ;