title: Use operator<< overload from a class A within another class B to display content of class A object
body: <p>My problem is as follows : I have two classes, one is Tree, and another one is Node. As you may have understand, Tree performs operations using Nodes objects.
  As debug, I would like to use a Node &lt;&lt; overload to display node content. For example :</p>
  <pre><code>class Tree {
  (....)
      void InsertNode(Node *node){
        std::cout &lt;&lt; node &lt;&lt; std::endl; // I would like this to display for example node._data and other information
       }
  
  }
  </code></pre>
  <p>What I've tried is first the &quot;classical solution&quot; I've always worked with, putting &lt;&lt; overload outside of Node Class, but Tree still does not call this function.</p>
  <pre><code>std::ostream&amp; operator&lt;&lt;(std::ostream&amp; os, Node &amp;node)
      {
          os &lt;&lt; &quot;Node value here &quot; &lt;&lt; node.getData();
          return os;
      }
  </code></pre>
  <p>I have also tried to put it directly in Node class:</p>
  <pre><code>class Node 
  {
       public: 
       (...)
  
      std::ostream&amp; operator&lt;&lt;(std::ostream&amp; os)
      {
          os &lt;&lt; &quot;Node here &quot; &lt;&lt; getData();
          return os;
      }
  }
  </code></pre>
  <p>But none of these solutions worked, the overload is not even called. Is it possible to perform such an action ? How can I do so ?</p>
  <p>Thanks a lot by advance,</p>