title: Stack Inheritance
body: <p>I have just finished a project for Post Fix Notation(RPN) using stack. I am not having much luck with some of the compiler errors so I come to you guys while I work on debugging on my side also.</p>
  
  <p>This file given to us. We are suppose to derive a stack class from it.</p>
  
  <pre><code>#ifndef ABSTRACTSTACK_H
  #define ABSTRACTSTACK_H
  
  #include &lt;string&gt;
  
  using namespace std;
  
  /* ---------------  Class 'Oops' ---------------
  Class 
  Thrown when an error is encountered.
  Member 'm_msg' stores an error message.
  */
  class Oops
  {
      string m_errormsg;
      public:
      Oops(string msg) : m_errormsg(msg) {}
      const string&amp; getMsg() const
      {
          return m_errormsg;
      }
  };
  
  
  /* ---------------  Abstract Class AbstractStack --------------- */
  template &lt; typename T &gt;
  class AbstractStack
  {
  public:
  
    // Purpose: Checks if a stack is empty
    // Returns: 'true' if the stack is empty
    //     'false' otherwise
    virtual bool isEmpty() const = 0;
  
  
    // Purpose: looks at the top of the stack
    // Returns: a const reference to the element currently on top of the stack
    // Exception: if the stack is empty, THROW a 'Oops' object with an error message!!!
   virtual const T&amp; top() const throw ( Oops ) = 0;
  
    // Purpose: push an element into the stack
    // Parameters: x is the value to push into the stack
    // Postconditions: x is now the element at the top of the stack,
    virtual void push(const T&amp; x) = 0;
  
    // Purpose: pop the stack
    // Postconditions: the element formerly at the top of the stack has
    // been removed
    // Note: Poping an empty stack results in an empty stack.
    virtual void pop() = 0;
  
  
    // Purpose: clears the stack
    // Postconditions: the stack is now empty
    virtual void clear() = 0;
  
  };
  
  #endif
  </code></pre>
  
  <p>Here is my derived class and it's implementation.</p>
  
  <pre><code>#ifndef STACK_H
  #define STACK_H
  
  #include&lt;string&gt;
  #include&lt;iostream&gt;
  #include&lt;cstdlib&gt;
  #include "abstractstack.h"
  using namespace std;
  
  
  
  template&lt;typename T&gt;
  struct Node
  {
      T Data;
      Node&lt;T&gt;* next;
  };
  
  
  template&lt;typename T&gt; 
  class Stack : public AbstactStack&lt;T&gt;
  {
  private:
  Node&lt;T&gt;* Top;
  
  public:
  
  //Purpose: Destructor
  //Postconditions: The stack is now empty
  ~Stack() {};
  
  //Purpose: Default Constructor
  //Postconditions: Top is initialized to 'NULL'
  Stack(); Top(NULL){};
  
  //Overloaded = Operator
  //Postconditions: *this is now equal to rhs
  const Stack&lt;T&gt;&amp; operator = (const Stack&lt;T&gt;&amp; rhs);
  
  
  //Purpose: Check if a stack is empty
  //Returns: 'true' if the stakc is empty, 'false' otherwise
  bool isEmpty() const;
  
  //Purpose: Looks at the top of the stack
  //Returns: a const reference to the element currently on top of the stack
  //Exception: if the stack is empty, THROW a 'Oops' object with an error message!!!"
  const T&amp; top() const throw(Oops);
  
      //Purpose: push an element into the stack
      //Parameters: x is the value to push into the stack
      //Postconditions: x is now the element at the top of the stack
      void push(const T&amp; x);
  
       //Purpose: pop the stack
      //Postconditions: the element formerly at the top of the stack has been removed
     //Popping an empty stack results in an empty stack
     void pop();
  
      //Purpose: clears the stack
      //Postconditions: the stack is now empty
      void clear();
  
      //Reverses the stack
      //Postconditions: stack is now in reverse order
      void reverse();
  };
  
  #include "stack.hpp"
  #endif
  </code></pre>
  
  <p>Implementation (.hpp)</p>
  
  <pre><code>#include &lt;string&gt;
  #include &lt;iostream&gt;
  using namespace std;
  
  
  
  template&lt;typename T&gt;
  const Stack&lt;T&gt;&amp; Stack&lt;T&gt;::operator = (const Stack&lt;T&gt;&amp; rhs)
  {
      if (this != &amp;rhs)
       {
          if (Top != NULL)
               clear();
  
          Node&lt;T&gt;* rhsPtr = rhs.Top;
          Node&lt;T&gt;* copyPtr = Top = new Node&lt;T&gt;;
          copyPtr-&gt;Data = rhsPtr-&gt;Data;
          while (rhsPtr-&gt;next != NULL)
          {
              rhsPtr = rhsPtr-&gt;next;
              copyPtr-&gt;next = new Node&lt;T&gt;;
              copyPtr = copyPtr-&gt;next;
              copyPtr-&gt;Data = rhsPtr-&gt;Data;
          }
          copyPtr-&gt;next = NULL;
      }
      return(*this)
  }
  
  template&lt;typename T&gt;
  Stack&lt;T&gt;::Stack(const Stack&lt;T&gt;&amp; rhs)
  {
      Top = NULL;
      *this = rhs;
  }
  
  template&lt;typename T&gt;
  bool Stack&lt;T&gt;::isEmpty()
  {
      return(Top == NULL);
  }
  
  template&lt;typename T&gt;
  const T&amp; top() const throw(Oops)
  {
      if (Top != NULL)
          return(Top-&gt;Data);
      else
          throw Oops(Stack is Empty!);
  
  }
  
  template&lt;typename T&gt;
  void Stack&lt;T&gt;::push(const T&amp; x)
  {
      Node&lt;T&gt;* newNode = new Node;
      newNode-&gt;Data = x;
  
      if (isEmpty())
     {
        Top = newNode;
        return;
      }
  
      newNode-&gt;next = Top;
      Top-&gt;next = newNode;
  
  }
  
  template&lt;typename T&gt;
  void Stack&lt;T&gt;::pop()
  {
      Node&lt;T&gt;* temp;
      if (Top != NULL)
      {
          temp = Top;
          Top = Top-&gt;next;
          delete temp;
      }
   }
  
  template&lt;typename T&gt;
  void Stack&lt;T&gt;::clear()
  {
      Node&lt;T&gt;* temp;
      while (Top != NULL)
      {
          temp = Top;
          Top = Top-&gt;next;
          delete temp;
      }
  }
  
  template&lt;typename T&gt;
  void Stack&lt;T&gt;::reverse()
  {
      Node&lt;T&gt;* current;
      Node&lt;T&gt;* previous;
      Node&lt;T&gt;* next;
  
      previous = NULL;
      current = Top;
      while (current != NULL)
      {
          next = current-&gt;next;
          current-&gt;next = previous;
          previous = current;
          current = next;
      }
  
      Top = previous;
  }
  </code></pre>
  
  <p>The compiler is unhappy with my Stack class. "stack.h:25:34: error: expected template-name before ‘&lt;’ token
   class Stack : public AbstactStack</p>
  
  <p>I've been told that I cannot inherit from Abstract because it is not a class but my professor tells me that it is fine and that I should add a forward declaration in my .cpp of Stack but I'm not sure how this goes. I know I am far from done but I would like to be able to solve at least this error so I can see if my program works correctly or not.</p>
  
  <p>I posted my main program into Pastebin with its headers and implementation here in case it is needed. <a href="http://pastebin.com/1t2YGa2c" rel="nofollow">http://pastebin.com/1t2YGa2c</a></p>