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.
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.
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.
A friend function is required when a function needs to access two or more independent classes, internal members. On the other hand, a friend class is needed when a class requires accessing the members of another class. When
a multiple member function needs to be a friend of that function, in that case, it is better to use friend class.
To learn C++
Call us @ 9825618292
Visit us @ http://tccicomputercoaching.com/workshop/