im trying to create a short email based program that displays only the subject of each email and how many emails with that specific subject there are. However im having a few scoping errors i cant figure out in my SearchCommunication. Can anyone take a look at it and let me know what i need to do to fix the errors?

#include <iostream>
#include <string>
#include <cstddef>

using namespace std;

string line;
int sum = 0;

class List
{
public:
	List();  //DEFAULT CONSTRUCTOR
   	List(const List& aList);   //COPY CONSTRUCTOR
	~List();  //DESTRUCTOR

//LIST OPERATIONS
	void InsertBeg(string, int);
	void Display();
private:
	struct ListNode
	{
		string name;
		int item;
		ListNode* next;
		ListNode* prev;
	}; //END ListNode
	int size;
	ListNode* head;
    	void CopyList(ListNode* ListPtr, ListNode* &NewListPrt);
	void DeleteList(ListNode* BeginPtr);   //DESTRUCTOR
	void SearchCommunication(string);
	void DeleteCommunication(string);
};//List

List inbox;

List::List()  //DEFAULT CONSTRUCTOR
{
	head = NULL;
	size = 0;
}

List::List(const List& aList)   //COPY CONSTRUCTOR
{
	CopyList(aList.head,head);
	size = aList.size;
}


List::~List()  //DESTRUCTOR
{
	DeleteList(head);
}
    
		//LIST OPERATIONS
void List::InsertBeg(string inputN, int Value)
{ 
	ListNode* Temp = head;
	head = new ListNode;
	head -> prev = NULL;
	head -> next = Temp;
	head -> name = inputN;
	head -> item = Value; 
	Temp -> prev = head;
	++size;
} //END InsertBeg()

void List::Display()
{
	ListNode* current = head;
	while (current != NULL)
	{
		cout << current -> name << " - " << current -> item;
		current = current -> next;
	}
} //END Display()

void List::CopyList(ListNode* ListPtr, ListNode *& NewListPtr)   //COPY CONSTRUCTOR
{
	 if (ListPtr != NULL)
	 {//COPY FIRST NODE}
		 NewListPtr = new ListNode;
		 NewListPtr -> item = ListPtr -> item;
		 NewListPtr -> name = ListPtr -> name;
		 NewListPtr -> next = ListPtr -> next;
		 NewListPtr -> prev = ListPtr -> prev;
		 //COPY REST (TAIL) OF LIST
		 CopyList(ListPtr -> next, NewListPtr -> next);
	 }
} //END

void List::DeleteList(ListNode* BeginPtr)   //DESTRUCTOR
{
	 if (BeginPtr != NULL)
	 {
     //DELETE TAIL OF LIST (ALL BUT FIRST NODE)
		DeleteList(BeginPtr -> next);
		delete BeginPtr;
	 }
} //END

//Searches the Inbox for a communication using subject as the key for the search, and
//returns a pointer to the communication node that matches the subject, or the null
//pointer if no such node is found.

void List::SearchCommunication(string word)
{
    ListNode *temp = inbox.head;
	while((temp->name != word) && (temp != NULL))
	{
		temp = temp -> next;
	}
	return temp;
}

//Moves an e-mail to be displayed first.
void MoveEmail()
{
	
}

//Deletes a communication having a given subject.
void List::DeleteCommunication(string sub)
{
    MoveEmail(SearchCommunication(sub));
    inbox.~List();
    sum-=inbox.head.value;
}

//Inserts a new e-mail.
void InsertEmail()
{
    pos = SearchCom(line);
    if(pos==NULL){
        inbox.InsertBeg(line, 1);
		position -> innum.head;
    }else
    {
        pos 
        MoveEmail(pos);
    }
    sum++;
}

//Displays Inbox by listing the communication in the order they appear in the
//Inbox from the most recent to the oldest, i.e., from beginning of doubly-linked list
//of communications, displaying the subject and the number of e-mails in the communication.
void DisplayInbox()
{
    cout << "Inbox: total number of emails is " << sum << "." << endl << endl;
    inbox.Display();
}

int main()
{
    /*while(getline(cin,line) && line!="")
    {
        InsertEmail();
    }
    DisplayInbox();*/
//    cin >> line;
}

Okay my question is how do i get my "void List::SearchCommunication(string word)" to return a value. Right now im getting the error that it cannot return a value.

change void to ListNode. Keep in mind, ListNode is a private structure, so anything outside your class won't be able to make a type ListNode.

Edit:

Shoud be ok on keeping it private .... SearchCommunication(string); is also private.

Yeah thats not helping much. Its saying i have a syntax error now. Saying i need a ; after ListNode.

Did you change it in your function header as well?

class List
{
public:
...
private:
	struct ListNode	{
         ...
         };
         ...
	ListNode SearchCommunication(string);
};//List
...
ListNode List::SearchCommunication(string word){
    ListNode *temp = inbox.head;
    ...
    return temp;
}

Also, inbox was declared as a global variable. Not sure if that was intentional or not, but you may want to restructure the program so you don't need to declare it globally.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.