What is a friend class? | Sololearn: Learn to code for FREE!


What is a friend class?

5/19/2019 11:01:31 AM


5 Answers

New Answer


A friend class is a class that can access the private and protected members of the other class.


Refer link for the info on friend class - https://www.sololearn.com/learn/CPlusPlus/1899/


Friend class


I had never heard of a friend class until I reviewed some exam questions for a certificate focusing on C#. I thought it was a trick question, a fake class type, at first because it had never been used nor mentioned over the entire course. Is their use common in the real world and across languages? Thank you HonFu and Nagendra for your explanation and the link. The description somehow reminds me of a nested class. I still have not grasped how exactly it works. In the examples (link), the friend class looks on the one hand like a member of the "host" class, on the other hand the friend class is called on its own outside that class and not as a class member. I will have to re-read the article and Experiment with that some time. :-)


Friend class is used to access private data member of one by second class if it is a Friend of that class