Why do I get errors whilst assigning pointers to a linked list?

Hello,

I have a doubly linked list telephone directory programme. I have a function that makes the list whilst also making links with pointers to other structures as I go along. When I try to refer to them I get the errors detailed below.

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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

const int MAXRECS = 3; // maximum number of records

struct TeleType
{
	string name;
	string phoneNo;
	TeleType *nextaddr;
	TeleType *prevaddr;
};

void populate(TeleType *); // function prototype needed by main()
void display(TeleType *); // function prototype needed by main()
void remove(TeleType *); //function prototype for main()
void make_list();

TeleType *head, *current, *tail; // 3 pointers to structures of
								 // type TeleType
								 // get a pointer to the first structure in the list
TeleType head, tail, current;

int main()
{	
	cout << "The list will now be made" << endl;

	make_list();

	cout << "\nThe list consists of the following records:\n";

	display(head); // display the structures

	system("pause");

	return 0;
}

void make_list()
{
	//Input values for head structure
	populate(head);
	//Assign nextaddr pointer to current
	head->nextaddr = current;
	//Input values for current structure
	populate(current);
	//Assign current structure's newaddr and preaddr
	current->prevaddr = head;
	current->nextaddr = tail;
	//Input values for tail
	populate(tail);
	//Assign prevaddr pointer
	tail->prevaddr = current;
	//assign newaddr pointer as null to tail structure
	tail->nextaddr = NULL;
	// assign prevaddr pointer as current pointer  for tail structure
	return;
}

// input a name and phone number
void populate(TeleType *record) // record is a pointer to a
{ // structure of type TeleType

	cout << "Enter a name: ";
	getline(cin, record->name);

	cout << "Enter the phone number: ";
	getline(cin, record->phoneNo);

	return;
}

void display(TeleType *contents) // contents is a pointer to a
{ // structure of type TeleType

	while (contents != NULL) // display until end of linked list
	{
		cout << endl << setiosflags(ios::left)
			<< setw(30) << contents->name
			<< setw(20) << contents->phoneNo
			<< setw(20) << contents->prevaddr
			<< setw(20) << contents->nextaddr;
		contents = contents->nextaddr;
	}
	cout << endl;

	return;
}


1>------ Build started: Project: Exercise13.5_2, Configuration: Debug Win32 ------
'head': 'TeleType' differs in levels of indirection from 'TeleType *'
1>c:\users\kish\google drive\c++

error C2040: 'tail': 'TeleType' differs in levels of indirection from 'TeleType *'

error C2040: 'current': 'TeleType' differs in levels of indirection from 'TeleType *'
1>Done building project "Exercise13.5_2.vcxproj" -- FAILED.
1
2
3
4
TeleType *head, *current, *tail; // 3 pointers to structures of
								 // type TeleType
								 // get a pointer to the first structure in the list
TeleType head, tail, current;

You are trying to define two different variables, both called head, or current, or tail. You must have different identifiers. Rename one of the sets.

Once you do this, you'll also need to make sure the pointer to the, for example, head, actually points to the head object.
TeleType* phead = &head;

I also suggest not getting in the habit of using global variables. It'll bite you later on when you have more complex programs.
Hello,

I have since renamed and reassigned them. It is working just fine now. I am just working out of a textbook and will heed your advice.
Topic archived. No new replies allowed.