What is difference between friend function and friend class? tccicomputercoaching.com The Friend function and friend class in C++ are the techniques used to access the private members of a class by using friend keyword. Difference: Friend function is a function used with a friend keyword to grant a non-member function access to the private members of a class. Friend class is a class used with a friend keyword to access the private members of another class.
Use: A friend function can be used in some situation of operator overloading. A friend class can be used when a class is created on the top of another class. The first condition is that friend function is not inherited by a child class. The second condition is that storage class specifier may not be present in friend function, which means that it cannot be declared as static and extern. The friend class can be declared in more than a single class. It is considered as a short alternative method for friend function because with the help of this we can create a friend class which can access the whole data members and function instead of creating multiple friend functions.