When private data from a class needs to be accessed directly without utilizing an object from that class, the friend function in C++ is utilized. Operator overloading is also done with friend functions. Operator overloading works similarly to function overloading in that it allows operators to be overloaded.