What is friend function ?
Friend Function :-
A friend function is a function that access private data variables of another class. The measure different between an ordinary class function and a member function is that the ordinary function access the object that involves the member to be passed by reference or value.
Example :- class sum
{
Private:
Int a,b,c;
Public:
Void get dada ()
{
Cout>>a>>b;
}
Void show data ()
{
Cout <<”sum”<<c
Friend void(sum x)
}
Void add (sum x)
{
x.c=x.a+x.b
}
Void main()
{
Sum obj;
obj.get.data();
add(obj)
obj.showdata();
}
};
0bj.c=obj.a+obj.b if we use it in main() then it will be wrong
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment