What is a friend?
We didn’t pay much attention to it yet, but we already saw the “public” and “protected” keywords in our class definitions. There is also the “private” keyword.
class cube : public body {
cube (const float, const Color &c);
virtual float GetVolume() const;
virtual float GetSurface() const;
// the assignment operator
cube& operator= ( const cube & );
int private_member; // just to get the idea
All the green stuff following the “public” keyword is accessible for everybody.
All the red stuff following the “protected” keyword is accessible to member functions of this class, and to member functions of all derived classes.
All private members are accessible only to member functions of this class, and not even to member functions of derived classes (they have to go through public or protected member functions of this class to access the private members).
With the friend keyword, you can grant other classes or functions limited access to protected or private members or functions. “Only friends can get at your private parts.”