 Hello friends, I am Sanjay Gupta. In this video I am going to demonstrate you how you can compare values of two classes using friend function in C++. Before starting, you can connect with me by following these details which are available in front of you. You can download my app Techimus that is available on Google Play. You can search my channel on YouTube by typing my name Sanjay Gupta. You can open my channel. You can subscribe my channel if you want to watch various programming related videos and playlists. Here videos of various programming related concepts are available. Now coming on to the topic, you can see I have implemented a code for you which will compare elements of two different classes using friend function. So I have included a header file iostream, then namespace std is used using using keyword, then advanced declaration of class 2 is available here. This class 2 is declared because I am defining class 1 and inside class 1 I am using a word 2 and compiler will not know what is 2. So I have already declared it as a class here, then class 1 is defined, inside class 1 int a is an attribute, then inside public section read function is defined. It will display a message, enter a number on console, then that number will be stored inside a variable using scene. I have declared friend function using this statement friend void max 1 comma 2. So name of function is max, its return type is void and it will receive two arguments 1 and 2. Then I have terminated class 1. After class 1 class 2 is defined, it is also containing an attribute b. Similar to class 1 it is having read function, it will show enter a number message on console using cout and the number will be stored inside b using scene. Then same declaration is available here as it was available in class 1. Friend void max 1 comma 2. So name of function is max, it will receive two arguments 1 for class 1 and second for class 2. Then you can see definition of function max is available here. It is receiving first argument inside x and second argument inside y. First argument is of one type and second argument is of two type, 1 and 2 are classes. Then if condition is comparing x dot a and y dot b, so here a and b are attributes of class 1 and 2 and both are declared in private section. Still we are accessing members of classes which are private in a single function. This is because max is defined as friend of both the classes. If this condition is true, then class 1 values greater will be displayed otherwise class 2 values greater will be displayed on console. After defining this friend function definition, main is implemented. Here two objects a1 and a2 both from 1 and 2 classes are declared. Then a1 dot read, b1 dot read these read functions are called. Then max friend function is called. This is calling of friend function. So max will be called two arguments a1 and b1 will be passed that will be received in x and y. Then if condition will be compared and accordingly the results will be displayed on console. So this is the complete implementation of friend function in two different classes. I hope you have understood the demonstration. Now I am going to execute this code. It is asking first number. I am entering 20. It is asking second number. I am entering 40. You can see class 2 value is greater. It is showing as the result. I again execute it and first I am entering 40 and then I am entering 20. It is showing class 1 value is greater. So it is working in both the way. I hope you have understood the concept well. If you want to watch more programming related videos, you can search my channel on YouTube by my name Sanjay Gupta. Here various programming related videos are available. You can watch it and you can improve your programming skills. Thank you for watching this video.