When should you use ‘friend’ in C++?

I have been reading through the C++ FAQ and was curious about the friend declaration. I personally have never used it, however I am interested in exploring the language.

What is a good example of using friend?


Reading the FAQ a bit longer I like the idea of the << >> operator overloading and adding as a friend of those classes. However I am not sure how this doesn’t break encapsulation. When can these exceptions stay within the strictness that is OOP?

30 Answers
30

Leave a Comment