Review Questions

1:What's wrong with the following attempts at establishing friends?
  1. class snap {
        friend clasp;
         ...
    } ;
    class clasp {  ... } ;
    
  2. class cuff {
    public:
          void snip(muff &) {  ... }
          ...
    } ;
    class muff {
         friend void cuff::snip(muff &);
         ...
    } ;
    
  3. class muff {
          friend void cuff::snip(muff &);
         ...
    } ;
    class cuff {
    public:
          void snip(muff &) {  ... }
          ...
    } ;
    
2:You've seen how to create mutual class friends. Can you create a more restricted form of friendship in which only some members of class B are friends to class A and some members of A are friends to B? Explain.
3:What problems might the following nested class declaration have?
 class Ribs { private: class Sauce { int soy; int sugar; public: Sauce(int s1, int s2) : soy(s1), sugar(s2) { } ...

Get C++ Primer Plus, Fourth 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.