Write a C++ program to demonstrate Friend Function.
Code :-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Program Name - Program for Friend Function
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
#include<iostream.h>
#include<conio.h>
class value
{
int a, b;
public:
void assign()
{
a=25;
b=40;
}
friend int add(value v);
};
int add(value v)
{
return (v.a + v.b);
}
void main()
{
clrscr();
value v1;
v1.assign();
cout <<"Addition is :- "<<add(v1);
getch();
}
/***************************************************
OUT PUT
Addition is :- 65
*****************************************************/
Output :-Addition is :- 65
Addition is :- 65