title: error: expected declaration before } token (when trying to compile)
body: <p>I'm having a problem. I have the template and implementation for a stack in files <strong>stack.h</strong> and <strong>stack.hpp</strong>. Then I have an <strong>in2out.cpp</strong> file that converts infix expressions to outfix expressions and evaluates them. At the beginning of in2out.cpp I "#include stack.h". And inside <strong>stack.h (which is my interface)</strong> I "#include stack.hpp" <strong>(stack.hpp is my implementation)</strong>. I know this is weird but it's the way I'm required to do it.</p>
  
  <p>Anyways, my problem is, when I'm trying to compile these 3 files together. I get only 1 error which is in stack.h (my interface, listed below). The error is: </p>
  
  <pre><code>In file included from in2post.cpp:7:
  stack.h:49: error: expected declaration before â}â token
  </code></pre>
  
  <p>Line 49 is near the bottom. here is my stack.h file.</p>
  
  <pre><code>#ifndef STACK_H
  #define STACK_H
  
  #include &lt;iostream&gt;
  #include &lt;vector&gt;
  
  
  namespace cop4530 {
  
  template&lt;typename T&gt;
  class Stack {
  
   private:
   std::vector&lt;T&gt; v;
  
   public:
   Stack();
   ~Stack();
   Stack (const Stack&lt;T&gt;&amp;);
   //Stack (Stack&lt;T&gt;&amp;&amp; );
   Stack&lt;T&gt;&amp; operator= (const Stack &lt;T&gt;&amp;);
   //Stack&lt;T&gt; &amp; operator=(Stack&lt;T&gt; &amp;&amp;);
   bool empty() const;
   void clear();
   void push(const T&amp; x);
   //void push(T &amp;&amp; x);
   void pop();
   T&amp; top();
   const T&amp; top() const;
   int size() const;
   void print(std::ostream&amp; os, char ofc = ' ') const;
  
  };
  
  template&lt;typename T&gt;
  std::ostream&amp; operator&lt;&lt; (std::ostream&amp; os, const Stack&lt;T&gt;&amp; a);
  
  template&lt;typename T&gt;
  bool operator== (const Stack&lt;T&gt;&amp; a, const Stack &lt;T&gt;&amp; b);
  
  template&lt;typename T&gt;
  bool operator!= (const Stack&lt;T&gt;&amp; a, const Stack &lt;T&gt;&amp; b);
  
  template&lt;typename T&gt;
  bool operator&lt; (const Stack&lt;T&gt;&amp; a, const Stack &lt;T&gt;&amp; b);
  
  #include "stack.hpp"
  
  }    //this is line 49
  
  #endif
  </code></pre>
  
  <p>Here's my makefile:</p>
  
  <pre><code>CC = g++
  FLAGS = -Wall -pedantic
  DDD = -g
  
  in2post.x: in2post.cpp stack.h stack.hpp
      $(CC) $(FLAGS) $(DDD) -o in2post.x in2post.cpp
  </code></pre>
  
  <p>EDIT: Here's the beginning of Stack.hpp: (tell me if I should change or add something)
  EDIT2: I just decided to include the whole Stack.hpp. Some functions are blanked out cause I didn't need them or couldn't figure them out</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  
  template&lt;typename T&gt;
  Stack&lt;T&gt;::Stack(){}
  
  template&lt;typename T&gt;
  Stack&lt;T&gt;::~Stack(){
     v.clear();
  }
  
  template&lt;typename T&gt;
  Stack&lt;T&gt;::Stack(const Stack&lt;T&gt; &amp; S){
      v = S.v;
  }
  /*
  template&lt;typename T&gt;
  Stack&lt;T&gt;::Stack(Stack&lt;T&gt; &amp;&amp;){
  
  }
  */
  template&lt;typename T&gt;
  Stack&lt;T&gt; &amp; Stack&lt;T&gt;::operator=(const Stack&lt;T&gt; &amp; S){
      v = S.v;
      return *this;
  }
  /*
  template&lt;typename T&gt;
  Stack&lt;T&gt;::Stack&lt;T&gt; &amp; Stack&lt;T&gt;::operator=(Stack&lt;T&gt; &amp;&amp;){
  
  }
  */
  template&lt;typename T&gt;
  bool Stack&lt;T&gt;::empty() const {
      return v.empty();
  }
  
  template&lt;typename T&gt;
  void Stack&lt;T&gt;::clear(){
      while (!v.empty())
          v.clear();
  }
  
  template&lt;typename T&gt;
  void Stack&lt;T&gt;::push(const T&amp; x){
      v.push_back(x);
  }
  /*
  template&lt;typename T&gt;
  void Stack&lt;T&gt;::push(T &amp;&amp; x){
  
  }
  */
  template&lt;typename T&gt;
  void Stack&lt;T&gt;::pop(){
      v.pop_back();
  }
  
  template&lt;typename T&gt;
  T&amp; Stack&lt;T&gt;::top(){
      return v[v.size()-1];
  }
  
  template&lt;typename T&gt;
  const T &amp; Stack&lt;T&gt;::top() const{
      return v[0];
  }
  
  template&lt;typename T&gt;
  int Stack&lt;T&gt;::size() const {
      return v.size();
  }
  
  template&lt;typename T&gt;
  void Stack&lt;T&gt;::print(std::ostream &amp; os, char ofc) const {
      for(int i = 0; i &lt; v.size(); i++)
      os &lt;&lt; v[i] &lt;&lt; ofc;
  }
  
  /*------------------NON-MEMBER GLOBAL FUNCTIONS-----------------*/
  
  template&lt;typename T&gt;
  std::ostream &amp; operator&lt;&lt;(std::ostream &amp; os, const Stack&lt;T&gt; &amp; a) {
      a.print(os);
      return os;
  }
  
  
  template &lt;typename T&gt;
  bool operator==(const Stack&lt;T&gt; &amp; a, const Stack&lt;T&gt; &amp; b) {
      if(a.size() != b.size())
              return false;
      else {
          Stack&lt;T&gt; c = a;
          Stack&lt;T&gt; d = b;
          bool retVal = true;
  
          while(!c.empty()) {
              if(c.top() == d.top()) {
               c.pop();
               d.pop();
              }
              else {
               retVal = false;
               break;
              }
          }
      return retVal;
      }
  }
  
  
  template &lt;typename T&gt;
  bool operator!=(const Stack&lt;T&gt; &amp; a, const Stack&lt;T&gt; &amp; b) {
      return !(a == b);
  }
  
  template &lt;typename T&gt;
  bool operator&lt;(const Stack&lt;T&gt; &amp; a, const Stack&lt;T&gt; &amp; b) {
      Stack&lt;T&gt; c = a;
      Stack&lt;T&gt; d = b;
      bool retVal = true;
  
      while(!c.empty()) {
          if(!(c.top() &lt; d.top())) {
            retVal = false;
            break;
          }
          else {
            c.pop();
            d.pop();
          }
      }
      return retVal;
  }
  </code></pre>