C++ class does not allow its private and protected members to be accessed outside the class. But this rule can be violated by making use of the “Friend” function.
As the name itself suggests, friend function is an external function that is a friend of the class. For friend function to access the private and protected methods of the class, we should have a prototype of the friend function with the keyword “friend” included inside the class.