Monday, 26 March 2018

To Create Friend Function

"Nice One Program"

#include<iostream.h>
#include<conio.h>
class A;                   //must declare first before use in B class
class B{
int b;
public:
B()
{ b=10;
}
friend void sum(A,B);

};
class A
{
int a;
public:
A()
{
a=20;
}
friend void sum(A,B);
};
void sum(A A1,B B1)
{
cout<<"Sum:"<<(A1.a+B1.b);

}
void main()
{         clrscr();
A obj1;
B obj2;
sum(obj1,obj2);
getch();
}










No comments:

Post a Comment