Chapter 14

A1:
  1. The friend declaration should be as follows:

    friend class clasp;
    
  2. This needs a forward declaration so that the compiler can interpret void snip(muff &):

    class muff;    // forward declaration
    class cuff {
    public:
    
        void snip(muff &) { ... }
          ...
      };
      class muff {
          friend void cuff::snip(muff &);
          ...
      };
    
  3. First, the cuff class declaration should precede the muff class so that the compiler can understand the term cuff::snip(). Second, the compiler needs a forward declaration of muff so that it can understand snip(muff &).

    class muff;    // forward declaration
    class cuff {
    public:
        void snip(muff &) { ... }
        ...
    };
    class muff {
        friend void cuff::snip(muff &);
        ...
    };
    
A2: No. For A to have a friend that's a member function of B, the B declaration must ...

Get The Waite Group's C++ Primer Plus, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.