title: Class Template and Reference Return Type
body: <p>Long-time reader, first-time poster!</p>
  
  <p>A few comments before I begin: I'm not looking for anyone to do my work for me, I just need a little guidance. Also, I've done a decent amount of googling, and I haven't been able to find any solutions yet.</p>
  
  <p>I have a class assignment that involves creating a template for the following class:</p>
  
  <pre><code>class SimpleStack
  {
  public:
    SimpleStack();
    SimpleStack&amp; push(int value);
    int pop();
  
  private:
    static const int MAX_SIZE = 100;
    int items[MAX_SIZE];
    int top;
  };
  
  SimpleStack::SimpleStack() : top(-1)
  {}
  
  SimpleStack&amp; SimpleStack::push(int value)
  {
    items[++top] = value;
    return *this;
  }
  
  int SimpleStack::pop()
  {
    return items[top--];
  }
  </code></pre>
  
  <p>Everything seems to work except <code>SimpleStack&amp; push(int value)</code>:</p>
  
  <pre><code>template &lt;class T&gt;
  class SimpleStack
  {
  public:
    SimpleStack();
    SimpleStack&amp; push(T value);
    T pop();
  
  private:
    static const int MAX_SIZE = 100;
    T items[MAX_SIZE];
    int top;
  };
  
  template &lt;class T&gt;
  SimpleStack&lt;T&gt;::SimpleStack() : top(-1)
  {}
  
  template &lt;class T&gt;
  SimpleStack&amp; SimpleStack&lt;T&gt;::push(T value)
  {
    items[++top] = value;
    return *this;
  }
  
  template &lt;class T&gt;
  T SimpleStack&lt;T&gt;::pop()
  {
    return items[top--];
  }
  </code></pre>
  
  <p>I keep getting the following errors on the definition of <code>SimpleStack&amp; push(int value)</code>: "use of class template requires template argument list," and "unable to match function definition to an existing declaration." </p>
  
  <p>Here is main if it helps:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;iomanip&gt;
  #include &lt;string&gt;
  #include "SimpleStack.h"
  using namespace std;
  
  int main()
  {
    const int NUM_STACK_VALUES = 5;
    SimpleStack&lt;int&gt; intStack;
    SimpleStack&lt;string&gt; strStack;
    SimpleStack&lt;char&gt; charStack;
  
    // Store different data values
    for (int i = 0; i &lt; NUM_STACK_VALUES; ++i)
    {
      intStack.push(i);
      charStack.push((char)(i + 65));
    }
    strStack.push("a").push("b").push("c").push("d").push("e");
  
    // Display all values
    for (int i = 0; i &lt; NUM_STACK_VALUES; i++)
      cout &lt;&lt; setw(3) &lt;&lt; intStack.pop();
    cout &lt;&lt; endl;
  
    for (int i = 0; i &lt; NUM_STACK_VALUES; i++)
      cout &lt;&lt; setw(3) &lt;&lt; charStack.pop();
    cout &lt;&lt; endl;
  
    for (int i = 0; i &lt; NUM_STACK_VALUES; i++)
      cout &lt;&lt; setw(3) &lt;&lt; strStack.pop();
    cout &lt;&lt; endl;
  
    return 0;
  }
  </code></pre>
  
  <p>Sorry for the excessive code pasting!</p>