The program I am working on deals with nested linked lists. I have a Olympics class that uses a linked list for events. Events have their own class with a linked list of contestants of a contestant class for each event.

I don't understand why I'm getting these compile errors:

379: error: `ListNode' has not been declared
380: error: ISO C++ forbids declaration of `node' with no type
: In function `Event* FindEventR(std::string, int*)':
386: error: `item' has not been declared
386: error: request for member of non-aggregate type before '->' token
388: error: `item' has not been declared
388: error: request for member of non-aggregate type before ';' token
391: error: `next' has not been declared
391: error: request for member of non-aggregate type before ')' token
: In function `Event* FindEvent(std::string)':
396: error: `head' undeclared (first use this function)
396: error: (Each undeclared identifier is reported only once for each function it appears in.)
: At global scope:
399: error: `ListNode' has not been declared
400: error: ISO C++ forbids declaration of `node' with no type
: In function `Event* AddSortedEventR(std::string, int*&)':
401: error: `item' has not been declared
401: error: request for member of non-aggregate type before ')' token
403: error: `ListNode' undeclared (first use this function)
403: error: `newPtr' undeclared (first use this function)
405: error: `head' undeclared (first use this function)
409: error: `next' has not been declared
409: error: request for member of non-aggregate type before ')' token

Everything is declared. I know its something wrong that I did, but I'm just not seeing it. Please any help would be appreciated. I'm sorry I'm attaching the code, but this program is more than just a few lines of code.

Attachments
#include <fstream>
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;

class Contestant
{
	public:
		void printContestant(std::ofstream &os);
		
	private:
		string firstName, lastName, age, country;
		friend class Event;
};

class Event
{
	typedef Contestant* ListItemType;
	/** A node on the list. */
	   
	public:
		/** Default constructor. */
		Event();

		/** Copy constructor.
		* @param aList The list to copy. */
		Event(const Event& aList);

		/** Destructor. */
		~Event();
	
		// List operations:
		bool isEmpty() const;
		int getLength() const;
		void AddContestant(Contestant *contestant, int pos = 0);
			//throw (ContestantException);
		void DeleteContestant(string first_name, string last_name);
			//throw (ContestantException);
		void SwapContestants(string first_name_one, string last_name_one, string first_name_two, string last_name_two);
			//throw (ContestantException);
		void PrintPosition(ostream &os, string first_name, string last_name);
			//throw (ContestantException);
		void Print(ostream &os);
	   
	private:
		struct ListNode
		{
			/** A data item on the list. */
			ListItemType item;
			/** Pointer to next node. */
			ListNode *next;
		}; // end ListNode
		
		/** Number of items in list. */
		int size;
		/** Pointer to linked list of items. */
		ListNode *head;
		
		string event_name;
		void AddContestantR(Contestant *Contestant, int pos, ListNode* &node, int depth = 0);
		void DeleteContestantR(std::string first_name, std::string last_name, ListNode* &node);
			//throw (ContestantException);
		void SwapContestantsR(string first_name_one, string last_name_one, string first_name_two, string last_name_two, ListNode* &node,
		ListNode** contestant_one, ListNode** contestant_two);
			//throw (ContestantException);
		void PrintPositionR(ostream &os, std::string first_name, std::string last_name, ListNode* node, int depth);
			//throw (ContestantException);
		void PrintR(ostream &os, ListNode* node, int depth);
		ListNode *find(int index) const;
		friend class Olympics;
		
};

class Olympics
{
	typedef Event* ListItemType;
	typedef pair<std::string, std::string> string_pair;
	
	private:
		struct ListNode
		{
			ListItemType item;
			ListNode *next;
		};
		
		ListNode *head;
		Event* FindEventR(string event_name, ListNode* node);
		Event* FindEvent(string event_name);
		Event* AddSortedEventR(string event_name, ListNode* &node);
		void PrintR(ostream &os, ListNode* node);

	public:
		Olympics();
		~Olympics();
		void AddContestant(string event_name, Contestant* contestant, int pos = 0);
			//throw (ContestantException);
		void DeleteContestant(string event_name, string first_name, string last_name);
			//throw (EventException, ContestantException);
		void SwapContestants(string event_name, string first_name_one, string last_name_one, string first_name_two, string last_name_two); 
			//throw (EventException, ContestantException);
		void PrintEventPosition(ostream &os, string event_name, string first_name, string last_name);
			//throw (EventException, ContestantException);
		void PrintEvent(ostream &os, string event_name);
			//throw (EventException);
		friend ostream& operator<<(ostream &os, Olympics &olympics); //void Print(ostream &os);
		
};

void Contestant::printContestant(ofstream &os)
{
	os << firstName << ' ' << lastName << ", " << country << endl;
}
	
Event::Event()
{
	size = 0;
	head = NULL;
}

Event::Event(const Event &aList):size(aList.size)
	{
	if (aList.head == NULL)
	  head = NULL;  // original list is empty

	else
	{  // copy first node
		head = new ListNode;
		head->item = aList.head->item;

		// copy rest of list
		ListNode *newPtr = head;  // new list pointer
		// newPtr points to last node in new list
		// origPtr points to nodes in original list
		for (ListNode *origPtr = aList.head->next;
		origPtr != NULL;
		origPtr = origPtr->next)
		{	
			newPtr->next = new ListNode;
			newPtr = newPtr->next;
			newPtr->item = origPtr->item;
		}  // end for

		newPtr->next = NULL;
	}  // end if
	}  // end copy constructor

Event::~Event()
{
	while (head != NULL)
	{
		ListNode *temp = head->next;
		delete head;
		head = temp;
	}
}


bool Event::isEmpty() const
{
	return size == 0;
}  // end isEmpty

int Event::getLength() const
{
	return size;
}  // end getLength

void Event::AddContestant(Contestant *contestant, int pos)
{
	AddContestantR(contestant, pos, head, 0);
}

void Event::DeleteContestant(string first_name, string last_name)
{
	DeleteContestantR(first_name, last_name, head);
}

void Event::SwapContestants(string first_name_one, string last_name_one, string first_name_two, string last_name_two) 
{
    //SwapContestantsR(first_name_one, last_name_one, first_name_two, last_name_two, node, **contestant_one, **contestant_two);
}

void Event::PrintPosition(ostream &os, string first_name, string last_name)
{
	int depth = 0;
	os << event_name << "Position: ";
	PrintPositionR(os, first_name, last_name, head, depth);
}

void Event::Print(ostream &os)
{
	os << event_name << "Contestants:  ";
	PrintR(os, head, 0);
}

void Event::PrintR(ostream &os, ListNode* node, int depth)
{
	if (node == NULL)
	{
	
	}

	else
	{
		//os << "("<< depth << ")" << node->item->printContestant(os);
		PrintR(os, node->next, depth+1);	
	}
}

void Event::PrintPositionR(ostream &os, std::string first_name, std::string last_name, ListNode* node, int depth)
//throw (ContestantException)
{
	if (node == NULL)
	{
		// throw ContestantException("Error: Contestant not found");
	}
	
	else if((node->item->firstName == first_name) && (node->item->lastName == last_name))
	{
		os << '(' << depth << ')' <<  first_name << " " << last_name << endl;
	}
	
	else
		PrintPositionR(os, first_name, last_name, node->next, depth+1);
}   

void Event::AddContestantR(Contestant *contestant, int pos, ListNode* &node, int depth)
//throw(ListIndexOutOfRangeException, ListException)
{
	if(pos == depth)
	{
		int newLength = getLength() + 1;

		if ( (pos < 0) || (pos > newLength) );
			//throw ListIndexOutOfRangeException("ListIndexOutOfRangeException: insert index out of range");
		else
		{  // try to create new node and place newItem in it
			//try
			{
				ListNode *newPtr = new ListNode;
				size = newLength;
				newPtr->item = contestant;

				// attach new node to list
				if (pos == 0)
				{  // insert new node at beginning of list
					newPtr->next = head;
					head = newPtr;
				}
				else
				{
					ListNode *prev = find(pos-1);
					// insert new node after node
					// to which prev points
					newPtr->next = prev->next;
					prev->next = newPtr;
				}  // end if
			}  // end try
		}
	}
	
	else if(node == NULL);
		//throw ListIndexOutOfRangeException("ListIndexOutOfRangeException: insert index out of range");
	
	else AddContestantR(contestant, pos, node->next, depth + 1);
}
	
	/*	int newLength = getLength() + 1;

		if ( (pos < 1) || (pos > newLength) );
			//throw ListIndexOutOfRangeException("ListIndexOutOfRangeException: insert index out of range");
		else
		{  // try to create new node and place newItem in it
			//try
			{
				ListNode *newPtr = new ListNode;
				size = newLength;
				newPtr->item = contestant;

				// attach new node to list
				if (pos == 1)
				{  // insert new node at beginning of list
					newPtr->next = head;
					head = newPtr;
				}
				else
				{
					ListNode *prev = find(pos-1);
					// insert new node after node
					// to which prev points
					newPtr->next = prev->next;
					prev->next = newPtr;
				}  // end if
			}  // end try
			/*catch (bad_alloc e)
			{
				throw ListException("ListException: memory allocation failed on insert");
			}  */// end catch
		//}  // end if
	//}  // end insert*/

void Event::DeleteContestantR(std::string first_name, std::string last_name, ListNode* &node)
//throw (ContestantException)
{
	/* See if we are at end of list. */
	if (node == NULL);
	//throw ListIndexOutOfRangeException("ListIndexOutOfRangeException: insert index out of range");

	else if ((node->item->firstName == first_name) && (node->item->lastName == last_name))
	{
		ListNode *tempNode = node;
		node = node->next;
		delete tempNode;
	}
	else DeleteContestantR(first_name, last_name, node->next);
}

void Event::SwapContestantsR(string first_name_one, string last_name_one, string first_name_two, string last_name_two, ListNode* &node,
ListNode** contestant_one, ListNode** contestant_two)
//throw (ContestantException)
{
	if(((*contestant_two)->item->firstName == first_name_one) && ((*contestant_one)->item->lastName == last_name_one) && 
	   (((*contestant_one)->item->firstName == first_name_two) && ((*contestant_one)->item->lastName == last_name_two)))
	{
		ListNode* tempnode = new ListNode();
		tempnode->next = node->next->next;
		node->next->next = node->next->next;
		node->next->next = tempnode->next;
	}
	else if(node == NULL)
	{
		//throwContestantException("Invalid contestants in swap");
	}
	else(first_name_one, last_name_one, first_name_two, last_name_two, node->next,
		contestant_one, contestant_two);
}

Event::ListNode *Event::find(int index) const
{
   if ( (index < 1) || (index > getLength()) )
      return NULL;

   else  // count from the beginning of the list.
   {  ListNode *cur = head;
      for (int skip = 1; skip < index; ++skip)
         cur = cur->next;
      return cur;
   }  // end if
}

Olympics::Olympics()
{
	head = NULL;
}

Olympics::~Olympics()
{
	while (head != NULL)
	{
		ListNode *temp = head->next;
		delete head;
		head = temp;
	}
}

void Olympics::AddContestant(string event_name, Contestant* contestant, int pos)
{
	Event *Event = FindEventR(event_name, head);

	if (Event == NULL)
	{
		Event = AddSortedEventR(event_name, head);
	}
	
	Event->AddContestant(contestant, pos);
}

Event* FindEventR(string event_name, ListNode* node)
{
	if (node == NULL)
	{
		return NULL;
	}
	
	if (node->item->geteventName() == event_name)

The problem is that you defined ListNode as a private member of Event class. So you can't use that structure outside ListNode. Make the structure public or move it outside any class. If you leave it as public member of Event class then you have to use Event::ListNode in order to access/reference it.

It doesn't matter that I declared the Olympic class as a friend to the Event class?

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