 Hello friends, I am Sanjay Gupta. In this video, I am going to demonstrate you how you can implement the concept of friend class in C++. Before starting, you can note my information. You can connect with me by following these details. You can download my app Techimus that is available on Google Play. You can search my channel by typing my name Sanjay Gupta on YouTube search. You can open my channel. You can subscribe it if you want to watch various programming related videos and playlists which are available here. You can improve your programming skills by watching my videos. Now coming on to the topic. In this video, I will be demonstrating how you can implement the concept of friend class in C++. So in friend function, we can share attributes of two classes in a particular function. But in case of friend class, you can share all the members of a particular class with another class. So first I am including a header file, IO stream. Then I am using a namespace std. Then I am implementing class A. Here, two attributes I am declaring X and Y. Then in public section, I am implementing read function. It will ask two values from user. And L is for line termination. Using C in, I am going to read those values inside X and Y. Now I am declaring a statement friend class B. Here, class B is friend of class A. It means class B can access all the members of class A. Now I am implementing definition of class B. Public section, I am not declaring any attribute inside class B because I just want to access members of class A inside class B. So I am defining first function F1. And this F1 function will receive an argument of class A type. Then I am printing sum equals to A1 dot X plus A1 dot Y. Then second function that is F2. Inside this function, I am creating an object A2 of class A. Then I am calling its read function. Again, I am calling C out. It will display sum equals to A2 dot X plus A2 dot Y. So friends, this way you can see F1 is also processing attributes X and Y of class A. And this F2 function is also processing X and Y attributes of class A. In first F1 function, A1 is passed as argument. In F2 function, I have created an object inside this definition. I have called its read function and then I have added the values. So this is possible with the help of this friend class declaration. So B is sharing all the members of class A. That's why we can access all the members of class A inside class B. Now I am implementing main function. Inside main function, I am first declaring attribute, sorry, object A1 of class A, then B1 object of class B. Now, I am calling read function through A1 object. So this read function of class A will be called. Now I am going to call these F1 and F2 functions. These are defined inside class B. So these functions will be called using class B object. So you can see B1 is object of class B, F1 is name of function and A1 is class A argument which is passed inside F1 function. Then I am calling second function that is F2 using B1 object and then return 0. So this is the complete definition of this program. Main function is implemented properly. It is calling F1 and F2 functions using B1 object and B1 is representing class B. Now I am executing this code. It will display two outputs and both will be some of two different objects. One is passed from main function to F1 and second object A2 which is created inside F2. It is calling read function and then displaying the sum. So first I have to enter two numbers. I have entered two and four. You can see it is printing sum. This is because of F1 function. Now F2 function is called. It is asking two numbers again. So I am entering 10 and 20 and you can see another result. Sum equals to 30. So friends, I hope you have understood how we can share members of class A using class B through this friend class declaration. So this is the complete demonstration how you can implement the concept of friend class in C++. If you want to watch more programming related videos, you can open my channel by searching my name Sanjay Gupta in YouTube. Here various programming related videos are available. You can improve your programming skills by watching these videos. Thank you for watching this video.