SHOW FUNCTION OF ONE CLASS FRIEND OF ANOTHER CLASS

/*PROGRAM TO SHOW THE CONCEPT OF FUNCTION OF ONE CLASS FRIEND OF ANOTHER CLASS*/

#include<conio.h>

#include<iostream.h>

class xyz;

class abc

{

public:

void frnd_fun(xyz x);

};

class xyz

{

int a;

public:

void display();

friend void abc::frnd_fun(xyz x);

};

void xyz::display()

{

cout<<“Display functon of xyz class is executed”<<endl;

cout<<“Enter the value of a: “;

cin>>a;

}

void abc::frnd_fun(xyz x)

{

cout<<“Friend function of xyz defined in abc class is executed”<<endl;

cout<<“Value of a is: “<<x.a;

}

void main()

{

xyz x1;

abc a1;

clrscr();

x1.display();

a1.frnd_fun(x1);

getch();

}

Leave a Reply

Your email address will not be published. Required fields are marked *