Creating a linked-list using a function

Okay so Im getting a compile error when I declare the the PersonNode function. The error is "expected constructor, destructor, or type conversion before '*' token." I'm not sure what the problem is as I have just copied the code right out of the book.

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
#include <iomanip>
#include <iostream>
#include <string>
using namespace std;

PersonNode* CreateList();   //expected constructor, destructor, or        type   conversion before '*' token

int main()
{
	struct PersonNode
	{
		char gender;
		int age;
		string name;
		PersonNode* next;
	};
	CreateList(); // createList not declared in this scope
}


	PersonNode* CreateList()   //same error as in declaration
	{
		PersonNode* head;
		PersonNode* perPtr;
		head = NULL;
		perPtr = new PersonNode;
		while(perPtr != NULL)
		{
			cin.get(perPtr -> gender);
			cin.ignore(1000, '\n');
			cin >> perPtr -> age;
			cin.ignore(1000, '\n');
			getline(perPtr -> name);
			perPtr -> next = head;
			head = perPtr;
			perPtr = new PersonNode;
		}
		ptr = head;
		return ptr;

	}



Thanks...



Last edited on
move the struct PersonNode declearation part before the line u'r getting error. compiler has not seen this declaration when ur error line gets executed.
Topic archived. No new replies allowed.