Help as to why am I getting this error message

I am starting with linked lists. I get these errors when compiling this program:
Compiler: Default compiler
Executing g++.exe...
g++.exe "C:\Dev-Cpp\buildListForward.cpp" -o "C:\Dev-Cpp\buildListForward.exe" -I"C:\Dev-Cpp\lib\gcc\mingw32\3.4.2\include" -I"C:\Dev-Cpp\include\c++\3.4.2\backward" -I"C:\Dev-Cpp\include\c++\3.4.2\mingw32" -I"C:\Dev-Cpp\include\c++\3.4.2" -I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib"
C:\Dev-Cpp\buildListForward.cpp:4: error: expected constructor, destructor, or type conversion before '*' token
C:\Dev-Cpp\buildListForward.cpp:4: error: expected `,' or `;' before '*' token
C:\Dev-Cpp\buildListForward.cpp:5: error: expected constructor, destructor, or type conversion before '*' token
C:\Dev-Cpp\buildListForward.cpp:5: error: expected `,' or `;' before '*' token

C:\Dev-Cpp\buildListForward.cpp: In function `int main()':
C:\Dev-Cpp\buildListForward.cpp:35: error: `buildListForward' undeclared (first use this function)

C:\Dev-Cpp\buildListForward.cpp:35: error: (Each undeclared identifier is reported only once for each function it appears in.)

Execution terminated

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
  nodeType *buildListForward();
nodeType *buildListForward()
{
         nodeType *first, *last, *newNode;
         int num;
         cout<<"Enter a list of integers ending with -999.\n";
         cin >> num;
         first = NULL;
         while(num != -999)
         {
                   new = new nodeType;
                   assert(newNode != NULL);
                   newNode->info = num;
                   newNode->link = NULL;
                   if(first == NULL)
                   {
                            first = NULL;
                            last = NULL;
                   }
                   else
                   {
                       last->link = newNode;
                       last = newNode;
                   }
                   cin >> num;
        } //end while
        return first;
} // end buildListForward

int main()
{
    buildListForward();
}
                       
                       
> C:\Dev-Cpp\buildListForward.cpp:4: error: expected constructor, destructor, or type conversion before '*' token
Will the real line 4 please step forward.

1
2
3
4
nodeType *buildListForward();
nodeType *buildListForward()
{
         nodeType *first, *last, *newNode;


The first obvious question is where is nodeType actually declared?

At a first guess, you "conveniently" left out 2 or 3 header files because they didn't feature in your error messages.

As a further first guess, you're missing a ; at the end of your nodeType class in the header file you don't show us.
Thank you very much salem c
The program worked after I declared a structure
1
2
3
4
5
struct nodeType
{
       int info;
       nodeType *link;
}


Now I am still not sure how to run this function in a program.
I have this code now:
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
#include<iostream>
#include<cassert>
using namespace std;

struct nodeType
{
	int info;
	nodeType *link;
};

class list
{
public:
	
	void *buildListForward();
	
};
void *buildListForward()
{
	nodeType *buildListForward();
	nodeType *first, *last, *newNode;
	int num;
	cout <<"Enter a list of integers ending with-999.\n";
	cin >> num;
	first = NULL;
	while(num != -999)
	{
		newNode = new nodeType;
		assert(newNode != NULL);
		newNode->info = num;
		newNode->link = NULL;
		if(first == NULL)
		{
			first = newNode;
			last = newNode;
		}
		else
		{
			last->link = newNode;
			last = newNode;
		}
		cin >> num;
	} // end while
}// end buildListForward

int main()
{
	nodeType list;
	list.buildListForward();
}

When I try to compile and run the program I get this error message:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Compiling single file...
- Filename: C:\Documents and Settings\ALISON STUDENT\My Documents\ZolaMndeni\buildListForward.cpp
- Compiler Name: TDM-GCC 4.9.2 32-bit Release

Processing C++ source file...
--------
- C++ Compiler: C:\Program Files\Dev-Cpp\MinGW64\bin\g++.exe
- Command: g++.exe "C:\Documents and Settings\ALISON STUDENT\My Documents\ZolaMndeni\buildListForward.cpp" -o "C:\Documents and Settings\ALISON STUDENT\My Documents\ZolaMndeni\buildListForward.exe" -m32 -I"C:\Program Files\Dev-Cpp\MinGW64\include" -I"C:\Program Files\Dev-Cpp\MinGW64\x86_64-w64-mingw32\include" -I"C:\Program Files\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include" -I"C:\Program Files\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++" -L"C:\Program Files\Dev-Cpp\MinGW64\x86_64-w64-mingw32\lib32" -static-libgcc -m32
C:\Documents and Settings\ALISON STUDENT\My Documents\ZolaMndeni\buildListForward.cpp: In function 'int main()':
C:\Documents and Settings\ALISON STUDENT\My Documents\ZolaMndeni\buildListForward.cpp:49:7: error: 'struct nodeType' has no member named 'buildListForward'
  list.buildListForward();
       ^


Compilation results...
--------
- Errors: 1
- Warnings: 0
- Compilation Time: 2.81s
Lines 18 to 20 should look like this
1
2
3
void *list::buildListForward()  //!! This is a member function, so make it a member function
{
    //!! nodeType *buildListForward();  You have no such function, so don't prototype non-existent things. 
Topic archived. No new replies allowed.