issue with pointer type private class function

Working on a linked list implementation program but I'm getting an error in one of the member functions of my class that I commented out below.

template <class T>
class LinkedList: public ABCList<T> {

private:
struct ListNode{

T Data;
ListNode *next;
};
ListNode *head;
int count;
ListNode* find(int pos);

public:
LinkedList();
bool isEmpty ();
int getLength () ;
void insert (int pos, T item) ;
T remove (int pos) ;
T retrieve (int pos) ;
};


//MEMBER FUNCTION DEFINITION

template<class T>
ListNode* LinkedList<T>::find(int pos) //THIS IS WHERE THE ERROR IS IT SAYS THAT
ListNode E ISN'T A VALID Type
EVEN THOUGH I clearly defined the
funtion with type ListNode
pointer as a private member function.
{
ListNode *n = head;
for (int i=1;i<pos;i++) {
n=n->next;
}
return n;
}

Thanks in Advance! :)
But ListNode is only defined inside your class, and you've put your function definition outside the class body. Try this:

1
2
3
4
5
template <class T>
typename LinkedList<T>::ListNode* LinkedList<T>::find(int pos)
{
        // Function body
}
Last edited on
Topic archived. No new replies allowed.