title: Overloading << operator on template classes
body: <p>I have made a template class for a node in a linked list and I'm trying to have it output its contents to an output stream by overloading &lt;&lt;. However my current code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  template&lt;class NType&gt; class Node;
  
  template&lt;class NType&gt;
  class Node {
  private:
          void deletePointer(NType* p);
  public:
          NType data;
          Node *prev, *next;
  
          template&lt;typename T&gt;
          struct is_pointer { static const bool value = false; };
  
          template&lt;typename T&gt;
          struct is_pointer&lt;T*&gt; { static const bool value = true; };
  
          Node();
          Node(NType data);
          ~Node();
  };  
  
  int main() {
          Node&lt;int&gt; *n1 = new Node&lt;int&gt;();
          Node&lt;int&gt; *n2 = new Node&lt;int&gt;(10);
  
          std::cout &lt;&lt; "Node 1: " &lt;&lt; n1 &lt;&lt; std::endl;
          std::cout &lt;&lt; "Node 2: " &lt;&lt; n2 &lt;&lt; std::endl;
  }
  
  template&lt;class NType&gt; inline std::ostream &amp; operator &lt;&lt; (std::ostream&amp; out, const Node&lt;NType&gt; &amp;node){
          out &lt;&lt; node.data;
          return out;
  }
  
  template&lt;class NType&gt; inline Node&lt;NType&gt;::Node()
              :data(NULL), prev(NULL), next(NULL)
  {
  }
  
  template&lt;class NType&gt; inline Node&lt;NType&gt;::Node(NType data)
              :data(data), prev(NULL), next(NULL)
  {
  }
  
  template&lt;class NType&gt; inline Node&lt;NType&gt;::~Node(){
          if(is_pointer&lt;NType&gt;::value){
                  deletePointer(&amp;data);
          } else {
                  return;
          }
  }
  
  template&lt;class NType&gt; inline void Node&lt;NType&gt;::deletePointer(NType* p){
      delete p;
  }
  </code></pre>
  
  <p>Outputs memory locations rather than the data within the nodes. This happens with primitive types such as <code>int</code> and the like as if it didn't know what kind of data was in the <code>NType</code> container.</p>
  
  <pre><code>Node 1: 0x741010
  Node 2: 0x741030
  Node 3: 0x741070
  Node 4: 0x741090
  </code></pre>
  
  <p>I've tried using <code>typename</code> rather than <code>class</code> but still no dice... Is there any way to dynamically find out what type the template is using and cast or something prior to insertion? I know I can make a ton of redundant code for all the primitives but that seems wasteful and unnecessary.</p>
  
  <p>If it helps any, I'm compiling on Arch Linux x64 with GCC v4.6.2 20111223</p>
  
  <p><B>Edit:</B> Since a lot of people are mentioning it. I've also tried putting the class outside as a friend and as a stand alone function neither of which work because the stream outputs address rather than the data itself regardless of where I put it. There are no private data values to be accessed so it's OK for it to not be a friend.</p>
  
  <p><B>Edit:</B>
  Test case: <a href="http://ideone.com/a99u5" rel="noreferrer">http://ideone.com/a99u5</a>
  Also updated source above.</p>
  
  <p><B>Edit:</B>
  Added the remaining portion of my code to assist Aaron in his understanding of the code.</p>