class B; //forward declaration
class A
{
friendclass B;
int x;
public:
A(){cin>>x;}
void set()
{
cin>>x;
}
void display(B a); //just declaration
};
class B
{
friendclass A;
public:
int x;
B(){cin>>x;}
void set()
{
}
void display(A a)
{
cout<<a.x;
}
};
void A::display(B a) //now we have the definition of B, so can code the function
{
cout<<a.x;
}