Write a program to perform the friend function in C++?
#include<iostream.h>
#include<conio.h>
class
a
{
private:
int
i,j;
public:
a()
{
i=10;
j=20;
}
friend
void sum(a);
};
void
sum(a a1)
{
int
s;
s=a1.i+a1.j;
cout<<"after
addition result is "<<s;
}
void
main()
{
class
a a2;
sum(a2);
getch();
}
OUTPUT:-
after
addition result is
30
Comments
Post a Comment