title: Setting a value by a friend function which is a member function of another class
body: <p><code>setwidth()</code> is a member function of class <code>Box</code> and it is also a friend function of class <code>Sbox</code> which is setting the values of members <code>width</code> of both classes.</p>
  
  <p>The value of <code>width</code> of the class <code>Sbox</code> is not setting/coming out properly.</p>
  
  <pre><code>#include&lt;iostream&gt;
  
  using namespace std;
  
  class Sbox;
  
  class Box{
      private:
          double width;
      public:
          friend void printwidth(Box box);
          void setwidth(Sbox sbox, double wid);
  };
  
  class Sbox {
      private:
          double width;
      public:
          friend void Box::setwidth(Sbox sbox, double wid);
          void printwidth() {
              cout &lt;&lt; "the width of small box: " &lt;&lt; width; //this value is coming wrong
          }
  };
  
  void Box::setwidth(Sbox sbox, double wid) {
      width = wid;
      sbox.width = wid;
  }
  
  void printwidth(Box box) {
      cout &lt;&lt; "width of the box: " &lt;&lt; box.width &lt;&lt; endl;
  }
  
  int main() {
      Box box;
      Sbox sbox;
      box.setwidth(sbox, 10.77);
      printwidth(box);
      sbox.printwidth();
      return 0;
  }
  </code></pre>