#include<iostream.h>
#include<conio.h>
class two;            //Declaration of class
class one              //Friend class
{
private:
                int  x,y;
public:
                void get()
                                {
                                x=10;
                                y=20;
                                }
                //Friend function as member function with respect to class one and none-member function with respect to class two
                void show(two t);
};
class two
{
private:
                int z;
public:
                void get()
                                {
                                z=30;
                                }
                friend void one::show(two t);
};
void one::show(two t)
{
                cout<<"X = "<<x<<endl;
                cout<<"Y = "<<y<<endl;
                cout<<"Z = "<<t.z<<endl;
}
void main()
{
                one a;
                two b;
                clrscr();
                a.get();
                b.get();
                a.show(b);
                getch();
}

154.PNG

Advertisements