I have a rather simple question that I could normally debug myself, but I seem to be having quite the problem at this point in time.
I am creating a linked list data structure and I made two functions, one to return the front Elem and one to return the last Elem. The issue is that the compiler is saying that Elem does not define a type, when it does.
Here is the header file trimmed down the the relevant code:
class simpleList {
public:
//Returns a pointer to the first Elem of the list
simpleList::Elem* front();
//Returns a pointer to the last Elem of the list
simpleList::Elem* back();
private:
struct Elem {
char info;
Elem *next;
};
Elem *head;
};
and here is the .cpp file implementation of these two functions:
//Returns a pointer to the first Elem of the list
simpleList::Elem* simpleList::front()
{
return head;
}
//Returns a pointer to the last Elem of the list
simpleList::Elem* simpleList::back()
{
Elem * temp = head;
while( temp -> next != 0 )
temp = temp -> next;
return temp;
}
I have tried both scoping them to the class and just doing:
Elem* simpleList::front()
Elem* simpleList::back()
The error message is as follows:
simpleList.h:38:9: error: ‘Elem’ in ‘class simpleList’ does not name a type
simpleList.h:41:9: error: ‘Elem’ in ‘class simpleList’ does not name a type
Try this order for the class declaration: