What is a friend class/function? Why would you need it?

Shortly, friend class or function is a class or a function that declared friend of an other class. The idea behind friend class is to provide the access to the private and protected members or member functions of the friend class. There is a lot of controversial opinions on this topic and you should not usually use friends as it is a hole in your design. One of the examples where it's used is a momento design pattern.

No comments: