my problem is that when I try and run it it says 'SortedList' : cannot instantiate abstract class due to following members: 'bool BasicADT::isEmpty(void) const' : is abstract ...and... 'int BasicADT::getLength(void) const' : is abstract

can someone please tell me what I am doing wrong with my getLength and isEmpty.


BasicADT...

class BasicADT  // abstract base class
{
public:
   virtual bool isEmpty() const = 0;
   virtual int getLength() const = 0;
}; // end BasicADT

SortedList.h...

#include "BasicADT.h"

typedef int ListItemType; // This is not a template class!

class SortedList : public BasicADT
{
public:
// constructor:
   SortedList();

// SortedList operations:
   bool IsEmpty() const
   { return Head == 0;}
   int  GetLength() const
   { return size;}
   void sortedInsert(const ListItemType& newItem);
   void sortedRemove(const ListItemType& anItem);
   void sortedRetrieve(int index, ListItemType& anItem) const;

private:
   int size;
   class Node{
   public:
	   ListItemType info;
	   Node* next;
   };
   typedef Node* nodePtr;
   nodePtr Head;
}; // end SortedList

SortedList.cpp...

#include "SortedList.h"
#include <iostream>

   SortedList::SortedList()
   {
	   Head = NULL;
	   size = 0;
   }

   void SortedList::sortedInsert(const ListItemType& newItem)
   {
	   nodePtr newNode = new Node, it = Head;
	   newNode->info = newItem;
	   newNode->next = NULL;

	   if(IsEmpty())
	   {
		   size ++;
		   Head = newNode;
	   }
	   else
	   {
		   while(it->next && it->next->info < newItem)//traverse to last node
			   it = it->next;
		   newNode->next = it->next;
		   it->next = newNode;
		   size++;
	   }
   }

   void SortedList::sortedRemove(const ListItemType& anItem)
   {
	   nodePtr it, prev;
	   if(IsEmpty())
		   return;
	   else if(Head->info == anItem)//if first element
	   {
		   size --;
		   it = Head->next;
		   delete Head;
		   Head = it;
		   sortedRemove(anItem);//recall incase item appears multiple times at beginning
	   }
	   else
	   {
		   it = Head;
		   while(it->next)
		   {
			   if(it->info == anItem)
			   {
				   prev->next = it->next;
				   it = prev;
				   size --;
				   sortedRemove(anItem);//recall incase item reappears in a row
			   }
			   else
			   {
				   prev = it;
				   it = it->next;
			   }
			}
	   }
   }

   void SortedList::sortedRetrieve(int index, ListItemType& anItem) const
   {
	   int count = 1;
	   nodePtr it = Head;
	   if(index > size || isEmpty())//if index is greater than list size or list is empty
		   return;
	   else
	   {
		   while(it->next && count < index)
		   {
			   it= it->next;
			   count++;
		   }
		   anItem = it->info;
	   }
   }

main...

#include "SortedList.h"
#include <iostream>
using namespace std;

int main()
{
	SortedList myList;



	return 0;
}

found it, messed up and missdeclared isEmpty

Edited 4 Years Ago by jigglymig: n/a

are you getting this error??
1>SortedList.obj : error LNK2001: unresolved external symbol "public: virtual bool __thiscall SortedList::isEmpty(void)const " (?isEmpty@SortedList@@UBE_NXZ)
1>SortedList.obj : error LNK2001: unresolved external symbol "public: virtual int __thiscall SortedList::getLength(void)const " (?getLength@SortedList@@UBEHXZ)

Im doing the same program and for some reason it gives me this error do u know why???

This question has already been answered. Start a new discussion instead.