title: C++ Nested class in class template declaration
body: <p>I'm attempting to write a C++11 linked list implementation, with the linked list being a template class and its node being a nested class as follows:</p>
  
  <pre><code>template &lt;typename T&gt;
  class LinkedList {
  public:
      class Node;
      std::shared_ptr&lt;Node&gt; listSearch(const T &amp;input) const;
  
  private:
      std::shared_ptr&lt;Node&gt; head;
      std::shared_ptr&lt;Node&gt; tail;
  };
  
  template &lt;typename T&gt;
  class LinkedList&lt;T&gt;::Node {
  private:
      T data;
      std::shared_ptr&lt;Node&gt; next;
  }
  </code></pre>
  
  <p>I am assuming that the class Node is not a template in itself, but when LinkedList gets instantiated it creates the Node class as well.</p>
  
  <p>When I attempt to define the listSearch function as follows, I get an error: "template argument for template type parameter must be a type; did you forget 'typename'?". Can someone explain what is wrong?</p>
  
  <pre><code>template &lt;typename T&gt;
  std::shared_ptr&lt;LinkedList&lt;T&gt;::Node&gt; LinkedList&lt;T&gt;::listSearch(const T &amp;input) { ... }
  </code></pre>
  
  <p>Edit:</p>
  
  <p>Ok, so I recompiled with gcc and the error message was clearer. It wants the following:</p>
  
  <pre><code>std::shared_ptr&lt;typename LinkedList&lt;T&gt;::Node&gt; LinkedList&lt;T&gt;::listSearch(const T &amp;input) const { ... }
  </code></pre>
  
  <p>Why is the typename necessary before LinkedList::Node? Isn't it obvious that it's a type?</p>