title: C++: Template errors - Illegal use of type 'void'
body: <p>I am very new to C++ template, and learning it through small programming.<br>
   I'm definitely not understanding what is wrong -- at all.<br>
  Here is the code. </p>
  
  <h1>Reverse a linked List using a stack</h1>
  
  <pre><code>using namespace std;
  template&lt;typename T&gt;
  void Reverse( node&lt;T&gt; *front);
  template&lt;typename T&gt;
  void Display( node&lt;T&gt; *front);
  template&lt;typename T&gt;
  class node
  {
  public:
      T data;
      node&lt;T&gt; *next;
      node(){ next = NULL; }
      node(const T&amp; item, node&lt;T&gt; *nextnode = NULL )
      {
          data = item;
          next = nextnode;
      }
  };
  
  int main()
  {
      node&lt;int&gt; *front = NULL;
      int size, no;
      cout &lt;&lt; "Enter the size of list ";
      cin &gt;&gt; size;
      for (int i = 1; i &lt; size; i++)
      {
          cout &lt;&lt; "Enter the " &lt;&lt; i &lt;&lt; " element " &lt;&lt; endl;
          cin &gt;&gt; no;
          front = new node&lt;int&gt; ( no , front);
      }
      Reverse(front);
      Display(front);
      _getch();
      return 0;
  }
  template&lt;typename T&gt;
  void Reverse(node&lt;T&gt; *front)
  {
      node&lt;T&gt; *temp = front;
      stack&lt;T&gt; s;
      while (temp != NULL)
      {
          s.push(temp);        // Pushing the address into stack
          temp = temp-&gt;next;
      }
      temp = s.top();
      front = temp;
      s.pop();
      while (!s.empty())
      {
          temp-&gt;next = s.top();  // Popping the address from stack.
          s.pop();
          temp = temp-&gt;next;
      }
  temp-&gt;next = NULL;
  }
  
  template&lt;typename T&gt;
  void Display( node&lt;T&gt; *front)
  {
      node&lt;T&gt; *temp = front;
      while (temp != NULL)
      {
          cout &lt;&lt; temp-&gt;data &lt;&lt; "  ";
          temp = temp-&gt;next;
      }
      cout &lt;&lt; endl;
  }
  </code></pre>
  
  <p>I am getting following both errors ( errors 1 &amp; 2 )  for both functions ( i.e. Reverse() and Display() )<br>
  Error 1 ) error C2182: 'Reverse' : illegal use of type 'void'      </p>
  
  <p>Error 2) error C2998: 'int Reverse' : cannot be a template definition      </p>
  
  <p>Error 3) error C1903: unable to recover from previous error(s); stopping compilation.   </p>
  
  <p>I've tried every single thing I can think of. But could not succeed.    </p>