title: How do you write your class's data to wostringstream in C++?
body: <p>Say I have a class B which includes an array of class A, I want to use <strong>std::wostringstream</strong> to output the data in class B. I have overloaded the operator <code>&lt;&lt;</code> for Class B, but I just get 'E0349' and 'C2679' error.</p>
  <p>Definition of class A</p>
  <pre><code>class A
  {
  public:
      A();
      ~A();
      inline A(float _x, float _y, float _z) :
          x(_x), y(_y), z(_z)
      {
      }
      inline void Set(float _x, float _y, float _z);
  
      float x, y, z;
      friend std::ostream&amp; operator&lt;&lt;(std::ostream&amp; out, const A&amp; source);
      friend std::wostringstream&amp; operator&lt;&lt;(std::wostringstream&amp; out, const A&amp; source);
  private:
  
  };
  </code></pre>
  <p>Definition of class B</p>
  <pre><code>class B
  {
  public:
      A* ArrayOfA;
      bool Initialize(const A* samples,
          unsigned int count);
      friend std::wostringstream&amp; operator&lt;&lt;(std::wostringstream&amp; out, const B&amp; source);
  
      B();
      ~B();
  
  private:
  
  };
  </code></pre>
  <p>As you can see,class B have an array of class A.
  I have overloaded the operator <code>&lt;&lt;</code> for class A.</p>
  <pre><code>std::wostringstream&amp;
  operator&lt;&lt;(std::wostringstream&amp; out, const A&amp; source)
  {
      out &lt;&lt; '&lt;' &lt;&lt; source.x &lt;&lt; ',' &lt;&lt; source.y &lt;&lt; ',' &lt;&lt; source.z &lt;&lt; '&gt;';
  
      return out;
  }
  </code></pre>
  <p>Now, I want to use Class B like:</p>
  <pre><code>std::wostringstream wss;
  wss &lt;&lt; ClassB
  </code></pre>
  <p>But I can not.</p>
  <p>Here is the error code, I have overloaded operator <code>&lt;&lt;</code> for Class B</p>
  <pre><code>std::wostringstream&amp;
  operator&lt;&lt;(std::wostringstream&amp; out, const B&amp; source)
  {
  
      for (unsigned int i = 0; i &lt; 4; ++i)
      {
          out &lt;&lt; &quot;:&quot; &lt;&lt; source.ArrayOfA[i] &lt;&lt; std::endl;
          // ERROR:E0349 no operator &quot;&lt;&lt;&quot; matches these operands
          // ERROR:C2679 binary '&lt;&lt;' : no operator found which takes a right-hand operand of type'A' (or there is no acceptable conversion)
      }
  
      return out;
  
  }
  </code></pre>
  <p>Here is the full code. It's online compiler.</p>
  <p><a href="https://onlinegdb.com/SyIS4hEyD" rel="nofollow noreferrer">A little bit of long code sample, but with details</a></p>
  <p>The full code is in the URL.</p>
  <p>What is wrong? How would you send the <em>ArrayOfA</em> to <strong>std::wostringstream</strong>? If you just only use std::ostream, how would you get the string content like std::wostringstream? Is there anything wrong with my operator overloading?</p>