title: C++ cannot instantiate abstract class
body: <p>I'm having cannot instantiate abstract class and I don't seem to find why its giving me the error. The class is not abstract at all. I have done some research but can't find any light. I hope anyone can hep me.</p>
  
  <p>Here is part of the code, you guys need more I can provide. </p>
  
  <pre><code> #include &lt;cassert&gt;
      #include "PriorityQueueInterface.h"
      #include "LinkedSortedList.h"
      #include "PrecondViolatedExcep.h"
  
      template&lt;class ItemType&gt;
      class SL_PriorityQueue : public PriorityQueueInterface&lt;ItemType&gt;
      {
      private:
          LinkedSortedList&lt;ItemType&gt;* slistPtr;  // Pointer to sorted list of
                                                 // items in the priority queue
  
      public:
          SL_PriorityQueue();
          SL_PriorityQueue(const SL_PriorityQueue&amp; pq);
          ~SL_PriorityQueue();
  
          bool isEmpty() const;
          bool add(const ItemType&amp; newEntry);
          bool remove();
  
          /** @throw PrecondViolatedExcep if priority queue is empty. */
          ItemType peek() const throw(PrecondViolatedExcep);
      }; // end SL_PriorityQueue
  
      template&lt;class ItemType&gt;
      SL_PriorityQueue&lt;ItemType&gt;::SL_PriorityQueue()
      {
          slistPtr = new LinkedSortedList&lt;ItemType&gt;(); //Here is the error
      } // end default constructor 
  
      template&lt; class ItemType&gt;
      SL_PriorityQueue&lt;ItemType&gt;::SL_PriorityQueue(const SL_PriorityQueue&amp; pq) :
          listPtr(pq.listPtr)
      {
      } // end copy constructor 
  
      template&lt;class ItemType&gt;
      SL_PriorityQueue&lt;ItemType&gt;::~SL_PriorityQueue()
      {
      } // end destructor 
  
  
      template&lt; class ItemType&gt;
      bool SL_PriorityQueue&lt;ItemType&gt;::add(const ItemType&amp; newEntry)
      {
          slistPtr-&gt;insertSorted(newEntry);
          return true;
      } // end add
      template&lt; class ItemType&gt;
      bool SL_PriorityQueue&lt;ItemType&gt;::remove()
      {
          // The highest-priority item is at the end of the sorted list
          return slistPtr-&gt;remove(slistPtr-&gt;getLength());
      } // end remove 
  
      template&lt; class ItemType&gt;
      bool SL_PriorityQueue&lt;ItemType&gt;::isEmpty() const
      {
          return slistPtr-&gt;isEmpty();
      } // end isEmpty 
  
      template&lt;class ItemType&gt;
      ItemType SL_PriorityQueue&lt;ItemType&gt;::peek() const throw(PrecondViolatedExcep)
      {
          if (isEmpty())
              throw PrecondViolatedExcep("peekFront() called with empty queue.");
  
          // Priority queue is not empty; return highest priority item;
          // it is at the end of the sorted list
          return slistPtr-&gt;getEntry(slistPtr-&gt;getLength());
      } // end peek 
  </code></pre>
  
  <p>This is the main </p>
  
  <pre><code>#include &lt;iostream&gt;
  #include "SL_PriorityQueue.h"
  
  using namespace std;
  
  int main() {
  
      SL_PriorityQueue&lt;int&gt; queue;
  
      queue.add(2);
  
      return 0;
  }
  </code></pre>
  
  <p>The error is in the following line of the SL_PriorityQueue class</p>
  
  <pre><code>template&lt;class ItemType&gt;
  SL_PriorityQueue&lt;ItemType&gt;::SL_PriorityQueue()
  {
      slistPtr = new LinkedSortedList&lt;ItemType&gt;();
  } // end default constructor 
  </code></pre>
  
  <p>Finally, the LinkedSortedList in case someone needs it. </p>
  
  <pre><code>#include "SortedListInterface.h"
  #include "Node.h"
  #include "PrecondViolatedExcep.h"
  
  template&lt;class ItemType&gt;
  class LinkedSortedList : public SortedListInterface&lt;ItemType&gt;
  {
  private:
      Node&lt;ItemType&gt;* headPtr; // Pointer to first node in the chain
      int itemCount;           // Current count of list items
  
                               // Locates the node that is before the node that should or does
                               // contain the given entry.
                               // @param anEntry  The entry to find.
                               // @return  Either a pointer to the node before the node that contains
                               //    or should contain the given entry, or nullptr if no prior node exists.
      Node&lt;ItemType&gt;* getNodeBefore(const ItemType&amp; anEntry) const;
  
      // Locates the node at a given position within the chain.
      Node&lt;ItemType&gt;* getNodeAt(int position) const;
  
      // Returns a pointer to a copy of the chain to which origChainPtr points.
      Node&lt;ItemType&gt;* copyChain(const Node&lt;ItemType&gt;* origChainPtr);
  
  public:
      LinkedSortedList();
      LinkedSortedList(const LinkedSortedList&lt;ItemType&gt;&amp; aList);
      virtual ~LinkedSortedList();
  
      void insertSorted(const ItemType&amp; newEntry);
      bool removeSorted(const ItemType&amp; anEntry);
      int getPosition(const ItemType&amp; newEntry) const;
  
      // The following methods are the same as given in ListInterface:
      bool isEmpty() const;
      int getLength() const;
      bool remove(int position);
      void clear();
      ItemType getEntry(int position) const throw(PrecondViolatedExcep);
  }; // end LinkedSortedList
  
  template&lt;class ItemType&gt;
  LinkedSortedList&lt;ItemType&gt;::LinkedSortedList() : headPtr(nullptr), itemCount(0)
  {
  }  // end default constructor
  
  template&lt;class ItemType&gt;
  LinkedSortedList&lt;ItemType&gt;::LinkedSortedList(const LinkedSortedList&lt;ItemType&gt;&amp; aList)
  {
      headPtr = copyChain(aList.headPtr);
  }  // end copy constructor
  
  template&lt;class ItemType&gt;
  LinkedSortedList&lt;ItemType&gt;::~LinkedSortedList()
  {
      clear();
  }  // end destructor
  
  template&lt; class ItemType&gt;
  void LinkedSortedList&lt;ItemType&gt;::clear()
  {
      while (!isEmpty())
          remove(1);
  } // end clear 
  
  
  template&lt; class ItemType&gt;
  ItemType LinkedSortedList&lt;ItemType&gt;::getEntry(int position) const
  throw(PrecondViolatedExcep)
  {
      return LinkedSortedList&lt;ItemType&gt;::getEntry(position);
  } // end getEntry
  
  template&lt; class ItemType&gt;
  bool LinkedSortedList&lt;ItemType&gt;::remove(int position)
  {
      bool ableToRemove = (position &gt;= 1) &amp;&amp; (position &lt;= itemCount);
      if (ableToRemove)
      {
          Node&lt;ItemType&gt;* curPtr = nullptr;
          if (position == 1)
          {
              // Remove the first node in the chain
              curPtr = headPtr; // Save pointer to node
              headPtr = headPtr-&gt;getNext();
          }
          else
          {
              // Find node that is before the one to delete
              Node&lt;ItemType&gt;* prevPtr = getNodeAt(position - 1);
              // Point to node to delete
              curPtr = prevPtr-&gt;getNext();
              // Disconnect indicated node from chain by connecting the
              // prior node with the one after
              prevPtr-&gt;setNext(curPtr-&gt;getNext());
          } // end if
            // Return node to system
          curPtr-&gt;setNext(nullptr);
  
          delete curPtr;
          curPtr = nullptr;
          itemCount-- ; // Decrease count of entries
      } // end if
      return ableToRemove;
  } // end remove 
  
  template&lt; class ItemType&gt;
  bool LinkedSortedList&lt;ItemType&gt;::isEmpty() const {
  
      return itemCount == 0;
  }
  
  template&lt; class ItemType&gt;
  int LinkedSortedList&lt;ItemType&gt;::getLength() const {
  
      return itemCount;
  }
  
  
  template&lt; class ItemType&gt;
  bool LinkedSortedList&lt;ItemType&gt;::removeSorted(const ItemType&amp; anEntry)
  {
      bool ableToRemove = false;
      if (!LinkedSortedList&lt;ItemType&gt;::isEmpty())
      {
          int position = getPosition(anEntry);
          ableToRemove = position &gt; 0;
          if (ableToRemove)
              ableToRemove = LinkedSortedList&lt;ItemType&gt;::remove(position);
      } // end if
      return ableToRemove;
  } // end removeSorted 
  
  
  template&lt; class ItemType&gt;
  int LinkedSortedList&lt;ItemType&gt;::getPosition(const ItemType&amp; anEntry) const
  {
      int position = 1;
      int length = LinkedSortedList&lt;ItemType&gt;::getLength();
      while ((position &lt;= length) &amp;&amp;
          (anEntry &gt; LinkedSortedList&lt;ItemType&gt;::getEntry(position)))
      {
          position++;
      } // end while
      if ((position &gt; length) ||
          (anEntry != LinkedSortedList&lt;ItemType&gt;::getEntry(position)))
      {
          position = -position;
      } // end if
      return position;
  } // end getPosition 
  
  
  
  
  
  template&lt;class ItemType&gt;
  void LinkedSortedList&lt;ItemType&gt;::insertSorted(const ItemType&amp; newEntry)
  {
      Node&lt;ItemType&gt;* newNodePtr = new Node&lt;ItemType&gt;(newEntry);
      Node&lt;ItemType&gt;* prevPtr = getNodeBefore(newEntry);
  
      if (isEmpty() || (prevPtr == nullptr)) // Add at beginning
      {
          newNodePtr-&gt;setNext(headPtr);
          headPtr = newNodePtr;
      }
      else // Add after node before
      {
          Node&lt;ItemType&gt;* aftPtr = prevPtr-&gt;getNext();
          newNodePtr-&gt;setNext(aftPtr);
          prevPtr-&gt;setNext(newNodePtr);
      } // end if
  
      itemCount++;
  } // end insertSorted
  
    // Private Methods:
  
  template&lt;class ItemType&gt;
  Node&lt;ItemType&gt;* LinkedSortedList&lt;ItemType&gt;::copyChain(const Node&lt;ItemType&gt;* origChainPtr)
  {
      Node&lt;ItemType&gt;* copiedChainPtr;
      if (origChainPtr == nullptr)
      {
          copiedChainPtr = nullptr;
      }
      else
      {
          // Build new chain from given one
          copiedChainPtr = new Node&lt;ItemType&gt;(origChainPtr-&gt;getItem());
          copiedChainPtr-&gt;setNext(copyChain(origChainPtr-&gt;getNext()));
      }  // end if
  
      return copiedChainPtr;
  }  // end copyChain
  
  template&lt;class ItemType&gt;
  Node&lt;ItemType&gt;* LinkedSortedList&lt;ItemType&gt;::getNodeBefore(const ItemType&amp; anEntry) const
  {
      Node&lt;ItemType&gt;* curPtr = headPtr;
      Node&lt;ItemType&gt;* prevPtr = nullptr;
  
      while ((curPtr != nullptr) &amp;&amp; (anEntry &gt; curPtr-&gt;getItem()))
      {
          prevPtr = curPtr;
          curPtr = curPtr-&gt;getNext();
      } // end while
  
      return prevPtr;
  } // end getNodeBefore
  
  template&lt; class ItemType&gt;
  Node&lt;ItemType&gt;* LinkedSortedList&lt;ItemType&gt;::getNodeAt(int position) const
  {
      // Debugging check of precondition
      assert((position &gt;= 1) &amp;&amp; (position &lt;= itemCount));
      // Count from the beginning of the chain
      Node&lt;ItemType&gt;* curPtr = headPtr;
      for (int skip = 1; skip &lt; position; skip++)
          curPtr = curPtr-&gt;getNext();
      return curPtr;
  } // end getNodeAt 
  </code></pre>
  
  <p>EDIT:
  SortedListInterface code added</p>
  
  <pre><code>#pragma once
  template&lt;class ItemType&gt;
  class SortedListInterface
  {
  public:
  
      virtual void insertSorted(const ItemType&amp; newEntry) = 0;
  
  
      virtual bool removeSorted(const ItemType&amp; anEntry) = 0;
  
  
      negative integer. */
      virtual int getPosition(const ItemType&amp; anEntry) = 0;
  
  
      virtual bool isEmpty() const = 0;
  
  
      virtual int getLength() const = 0;
  
  
      virtual bool remove(int position) = 0;
  
      virtual void clear() = 0;
  
  
      virtual ItemType getEntry(int position) const = 0;
  }; 
  </code></pre>