This is a tutorial on how to use friend function in c++. The program is given below that adds two numbers using friend function. The program is extendable. Go enjoy the program. Lets begin…….
Program for friend function
//declare two classes.
one sum(two t);
cout<<“Sum = “<<a;
friend one one::sum(two);
//function of one
one one::sum(two t)
//clear the screen.
//declare x,z as one and y as two.
Sum = 4
The program can be extended by using the concept in any program.
- Remember this is a basic part of c++ which can be used in any program….
- Include ‘iostream.h’ and ‘conio.h’ files.
- Declare two classes.
- Declare friend function.
- Add void main.
- Start program by first clearing the screen.
- Declare the x,y,z as your class name.
- Call the functions.
At the end
You learnt creating the C++ program for friend function in c++. So now enjoy the program.
Please comment on the post and share it.
And like it if you liked.