SHOW CONCEPT OF OUTER FUNCTION FRIEND OF TWO CLASSES

/*PROGRAM TO SHOW CONCEPT OF OUTER FUNCTION FRIEND OF TWO CLASSES*/

#include<conio.h>

#include<iostream.h>

class tempB;

class tempA

{

int a;

public:

void get_a()

{

cout<<“Enter a: “;

cin>>a;

}

friend void display(tempA a1,tempB b1); //FRIEND FUNCTION DECLARATION

};

class tempB

{

int b;

public:

void get_b()

{

cout<<“Enter b: “;

cin>>b;

}

friend void display(tempA a1,tempB b1); //FRIEND FUNCTION DECLARATION

};

void display(tempA a1,tempB b1)          //FRIEND FUNCTION DEFINITION

{

int sum=0;

cout<<“Friend function executed”<<endl;

cout<<“Value of a is: “<<a1.a<<endl;

cout<<“Value of b is: “<<b1.b<<endl;

sum=a1.a+b1.b;

cout<<“Sum of a and b is: “<<sum;

}

void main()

{

tempA a1;

tempB b1;

clrscr();

a1.get_a();

b1.get_b();

display(a1,b1);

getch();

}

Leave a Reply

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