Linked lists problem / class

its not liking the "head" or "next".


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
1
1>  main.cpp
1>c:\users\administrator\documents\visual studio 2010\projects\hw_5b\hw_5b\employee.h(5): error C2143: syntax error : missing ';' before '*'
1>c:\users\administrator\documents\visual studio 2010\projects\hw_5b\hw_5b\employee.h(5): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\administrator\documents\visual studio 2010\projects\hw_5b\hw_5b\employee.h(5): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\administrator\documents\visual studio 2010\projects\hw_5b\hw_5b\employee.h(8): error C2371: 'Employee' : redefinition; different basic types
1>          c:\users\administrator\documents\visual studio 2010\projects\hw_5b\hw_5b\employee.h(5) : see declaration of 'Employee'
1>c:\users\administrator\documents\visual studio 2010\projects\hw_5b\hw_5b\employee.h(16): error C2061: syntax error : identifier 'ptrType'
1>c:\users\administrator\documents\visual studio 2010\projects\hw_5b\hw_5b\employee.h(17): error C2061: syntax error : identifier 'ptrType'
1>c:\users\administrator\documents\visual studio 2010\projects\hw_5b\hw_5b\employee.h(18): error C2061: syntax error : identifier 'ptrType'
1>c:\users\administrator\documents\visual studio 2010\projects\hw_5b\hw_5b\main.cpp(12): error C2660: 'Employee::insertItem' : function does not take 1 arguments
1>c:\users\administrator\documents\visual studio 2010\projects\hw_5b\hw_5b\main.cpp(19): error C2660: 'Employee::deleteItem' : function does not take 1 arguments
1>  Employee.cpp
1>c:\users\administrator\documents\visual studio 2010\projects\hw_5b\hw_5b\employee.h(5): error C2143: syntax error : missing ';' before '*'
1>c:\users\administrator\documents\visual studio 2010\projects\hw_5b\hw_5b\employee.h(5): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\administrator\documents\visual studio 2010\projects\hw_5b\hw_5b\employee.h(5): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\administrator\documents\visual studio 2010\projects\hw_5b\hw_5b\employee.h(8): error C2371: 'Employee' : redefinition; different basic types
1>          c:\users\administrator\documents\visual studio 2010\projects\hw_5b\hw_5b\employee.h(5) : see declaration of 'Employee'
1>c:\users\administrator\documents\visual studio 2010\projects\hw_5b\hw_5b\employee.h(16): error C2061: syntax error : identifier 'ptrType'
1>c:\users\administrator\documents\visual studio 2010\projects\hw_5b\hw_5b\employee.h(17): error C2061: syntax error : identifier 'ptrType'
1>c:\users\administrator\documents\visual studio 2010\projects\hw_5b\hw_5b\employee.h(18): error C2061: syntax error : identifier 'ptrType'
1>c:\users\administrator\documents\visual studio 2010\projects\hw_5b\hw_5b\employee.cpp(9): error C2065: 'head' : undeclared identifier
1>c:\users\administrator\documents\visual studio 2010\projects\hw_5b\hw_5b\employee.cpp(10): error C2448: 'Employee::insertItem' : function-style initializer appears to be a function definition
1>c:\users\administrator\documents\visual studio 2010\projects\hw_5b\hw_5b\employee.cpp(19): error C2065: 'head' : undeclared identifier
1>c:\users\administrator\documents\visual studio 2010\projects\hw_5b\hw_5b\employee.cpp(20): error C2448: 'Employee::deleteItem' : function-style initializer appears to be a function definition
1>c:\users\administrator\documents\visual studio 2010\projects\hw_5b\hw_5b\employee.cpp(51): error C2065: 'head' : undeclared identifier
1>c:\users\administrator\documents\visual studio 2010\projects\hw_5b\hw_5b\employee.cpp(52): error C2448: 'Employee::displayList' : function-style initializer appears to be a function definition
1>  Generating Code...
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
void Employee::deleteItem(ptrType & head)
{
	Employee * location = head;	
	Employee * place = head;		
	int item;

	cout << "Enter the ID of the item to be deleted:\t";
	cin >> item;

	if(head->id == item)	
	{
		cout << "The item has been deleted.\n\n";
		head = head->next;
		return;			
	}

	while((location->next != NULL) && (item != location->id)) 
	{
		place = location;							
		location = location->next;
	}
	
	if(location->id == item)
	{
		place->next = location->next;
		delete location;
		cout << "The item has been deleted.\n\n";
	}
	else
		cout << "The item is not in the list.\n\n";

}
void Employee::displayList(ptrType & head)
{
	Employee * temp = head;			

	while(temp != NULL)			
	{
		cout << "ID:\t" << temp ->id << endl;
		temp = temp->next;
	}
}
Last edited on
Line 1, 2 and 35

You are assigning the wrong type to Employee, most likely what this means:
1> c:\users\administrator\documents\visual studio 2010\projects\hw_5b\hw_5b\employee.h(5) : see declaration of 'Employee'


Make sure you are using the correct types in your assignments
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <string>
#include <iostream>
using namespace std;

typedef Employee* ptrType;

class Employee
{
private:
		int id;
		string name;
		Employee * next;

public:
		Employee();
		~Employee();
		void insertItem(ptrType & head);
		void deleteItem(ptrType & head);
		void displayList(ptrType & head);
};
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include "Employee.h"


typedef Employee* ptrType;

int main()
{
	Employee *head = NULL;	
	int count = 0;
	char answer;
	Employee employee;

	while (count < 4)
	{
		employee.insertItem(head);
		count++;
		system("cls");
	}
	
	if(toupper(answer) == 'Y')
	{
		employee.deleteItem(head);
	}
	
	cout << "Display List (Y/N)?";
	cin >> answer;

	if(toupper(answer) == 'Y')
	{
		employee.displayList(head);
	}

	return 0;
}
Topic archived. No new replies allowed.