Loading...
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Loading Lab...
A function that is NOT a member of a class but has permission to access the class's private and protected members.
class Box {
int width;
public:
friend void printWidth(Box b); // Friend!
};It's defined outside the class scope and doesn't have a this pointer.
Friendship is granted, not taken. The class must explicitly declare its "friends".
Friend functions are frequently used for overloading the insertion << and extraction >> operators for custom classes.