Create friend function in class
To create freind function of class
- Definition:-
Friend function is non-member function of class but still that access the private data of that class.
Friend function is declared in class but it not necessary object of class to call it call without object like simple functions.
#include<iostream.h>
#include<conio.h>
class ABC
{
int a;
Public:
void get()
{
cout<<"enter value of A : ";
cin>>a;
}
friend void show(ABC &);
};
void show(ABC &i)
{
cout<<"A = "<<i.a;
}
void main()
{
ABC A1;
A1.get();
show(&A1);
getch();
}
enter value of A : 10
A = 10

0 comments: