+9

What is a friend class?

5/19/2019 11:01:31 AM

Warwal

5 Answers

New Answer

+7

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

+4

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

+1

Friend class

+1

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. :-)

0

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