I have an object oriented programming with c++ course this semester at college and we were learning about friend functions.I instinctively dislike them for their ability to bypass the security that Encapsulation and Data hiding provide, I read a few articles on the internet and some people thought that it was a good idea with some legitimate uses.What would an OOPs expert say about friend fucntions in C++? Should I just skim over it or should I learn more about it?
C++ to friend or not to friend
c++;object oriented;friends
It is not always convenient to make all the functions related to a C++ class members of that class.  For example, imagine an implementation of vector algebra with scalar multiplication.  We want to write:  double a; Vector v, w; w = v * a;We can do this with a member function:public class Vector { ... Vector operator*(double a);}But we would also like to write:w = a * vThis requires a free function: Vector operator*(double a, Vector v)The friend keyword was added to C++ to support this usage.  The free function is part of the Vector class implementation, and should be declared in the same header and implemented in the same source file.  Similarly we may use friend to simplify the implementation of tightly coupled classes, like a collection and an iterator.  Again, I would declare both classes in the same header, and implement them in the same source file.