I'm trying to template a pointer-based list class and several functions (the ones in which I try to return a pointer) are producing error messages.
The class:
The functions:
I'm getting the same error on the first line of each of the above functions:
I've written constructors and destructors for the templated List class, so I'm not sure why only these three functions are giving me problems. The majority of my code for this project was copied out of the textbook, as per the assignment, so I'm not sure what the problem is. All of the other member functions seem to compile just fine.
Any help would be greatly appreciated!
The class:
Code:
template <typename T> class List : public BasicADT { public: List(); // constructor List(const List<T>& aList); // copy constructor virtual ~List(); // destructor // overloaded assignment operator List<T> & operator=(const List<T>& rhs); // member functions virtual bool isEmpty() const; virtual int getLength() const; virtual void insert(int index, const T& newItem); virtual void remove(int index); virtual void retrieve(int index, T& dataItem) const; virtual void removeAll(); private: struct ListNode { T item; ListNode *next; }; // end ListNode int size; ListNode *head; ListNode *find(int index) const; void copyListNodes(List<T> origList); protected: void setSize(int newSize); ListNode *getHead() const; void setHead(ListNode *ptr) const; T getNodeItem(ListNode *ptr) const; ListNode *getNextNode(ListNode *ptr) const; } ; // end List
Code:
template <typename T> ListNode *List<T>::find(int index) const { if ( (index < 1) || (index > getLength()) ) { return null; } else { ListNode *cur = head; for (int skip = 1; skip < index; ++skip) { cur = cur->next; } // end for return cur; } // end if } // end find template <typename T> ListNode *List<T>::getHead() const { return head; } // end getHead template <typename T> ListNode *List<T>::getNextNode(ListNode *ptr) const { return ptr->next; } // end getNextNode
Code:
error: expected constructor, destructor, or type conversion before '*' token
Any help would be greatly appreciated!
Comment