Not sure what this compile error is, help please

Well, I'm working on making a sort of "Map" program, which will basically function as a grid. My plan was to use a MapSquare class to hold information on the square, and use a MapList class to link them together, sort of like a Linked List, but multi-directional (NSEW)

now I'm running into an error I don't know.

MapList Class
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
#ifndef MAPLIST_H
#define MAPLIST_H


#include "mapSquares.h"


struct mapList
{
	mapSquares data;
	mapList *north;
	mapList *south;
	mapList *east;
	mapList *west;
};

//inserts a new square in each of the cardinal directions
mapList* insertN(mapList * &spot, mapSquares toAdd)
{
	mapList *newList;

	newList = new mapList;

	newList->data = toAdd;

	newList->south = spot;
	spot->north = newList;
	return spot;
}
mapList* insertE(mapList * &spot, mapSquares toAdd)
{
	mapList *newList;

	newList = new mapList;

	newList->data = toAdd;

	newList->west = spot;
	spot->east = newList;
	return spot;
}
mapList* insertW(mapList * &spot, mapSquares toAdd)
{
	mapList *newList;

	newList = new mapList;

	newList->data = toAdd;

	newList->east = spot;
	spot->west = newList;
	return spot;
}
mapList* insertS(mapList * &spot, mapSquares toAdd)
{
	mapList *newList;

	newList = new mapList;

	newList->data = toAdd;

	newList->north = spot;
	spot->south = newList;
	return spot;
}
#endif 


Error Report in Compiling
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
1
1>  main.cpp
1>c:\castle\maplist.h(9): error C2236: unexpected 'struct' 'mapList'. Did you forget a ';'?
1>c:\castle\maplist.h(9): error C2143: syntax error : missing ';' before '{'
1>c:\castle\maplist.h(9): error C2447: '{' : missing function header (old-style formal list?)
1>c:\castle\maplist.h(18): error C2143: syntax error : missing ';' before '*'
1>c:\castle\maplist.h(18): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\castle\maplist.h(18): error C2065: 'spot' : undeclared identifier
1>c:\castle\maplist.h(18): error C2275: 'mapSquares' : illegal use of this type as an expression
1>          c:\castle\mapsquares.h(5) : see declaration of 'mapSquares'
1>c:\castle\maplist.h(18): error C2146: syntax error : missing ')' before identifier 'toAdd'
1>c:\castle\maplist.h(18): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\castle\maplist.h(18): error C2078: too many initializers
1>c:\castle\maplist.h(18): error C2275: 'mapSquares' : illegal use of this type as an expression
1>          c:\castle\mapsquares.h(5) : see declaration of 'mapSquares'
1>c:\castle\maplist.h(18): error C2059: syntax error : ')'
1>c:\castle\maplist.h(19): error C2143: syntax error : missing ';' before '{'
1>c:\castle\maplist.h(19): error C2447: '{' : missing function header (old-style formal list?)
1>c:\castle\maplist.h(30): error C2143: syntax error : missing ';' before '*'
1>c:\castle\maplist.h(30): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\castle\maplist.h(30): error C2086: 'int mapList' : redefinition
1>          c:\castle\maplist.h(18) : see declaration of 'mapList'
1>c:\castle\maplist.h(30): error C2065: 'spot' : undeclared identifier
1>c:\castle\maplist.h(30): error C2275: 'mapSquares' : illegal use of this type as an expression
1>          c:\castle\mapsquares.h(5) : see declaration of 'mapSquares'
1>c:\castle\maplist.h(30): error C2146: syntax error : missing ')' before identifier 'toAdd'
1>c:\castle\maplist.h(30): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\castle\maplist.h(30): error C2078: too many initializers
1>c:\castle\maplist.h(30): error C2275: 'mapSquares' : illegal use of this type as an expression
1>          c:\castle\mapsquares.h(5) : see declaration of 'mapSquares'
1>c:\castle\maplist.h(30): error C2059: syntax error : ')'
1>c:\castle\maplist.h(31): error C2143: syntax error : missing ';' before '{'
1>c:\castle\maplist.h(31): error C2447: '{' : missing function header (old-style formal list?)
1>c:\castle\maplist.h(42): error C2143: syntax error : missing ';' before '*'
1>c:\castle\maplist.h(42): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\castle\maplist.h(42): error C2086: 'int mapList' : redefinition
1>          c:\castle\maplist.h(18) : see declaration of 'mapList'
1>c:\castle\maplist.h(42): error C2065: 'spot' : undeclared identifier
1>c:\castle\maplist.h(42): error C2275: 'mapSquares' : illegal use of this type as an expression
1>          c:\castle\mapsquares.h(5) : see declaration of 'mapSquares'
1>c:\castle\maplist.h(42): error C2146: syntax error : missing ')' before identifier 'toAdd'
1>c:\castle\maplist.h(42): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\castle\maplist.h(42): error C2078: too many initializers
1>c:\castle\maplist.h(42): error C2275: 'mapSquares' : illegal use of this type as an expression
1>          c:\castle\mapsquares.h(5) : see declaration of 'mapSquares'
1>c:\castle\maplist.h(42): error C2059: syntax error : ')'
1>c:\castle\maplist.h(43): error C2143: syntax error : missing ';' before '{'
1>c:\castle\maplist.h(43): error C2447: '{' : missing function header (old-style formal list?)
1>c:\castle\maplist.h(54): error C2143: syntax error : missing ';' before '*'
1>c:\castle\maplist.h(54): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\castle\maplist.h(54): error C2086: 'int mapList' : redefinition
1>          c:\castle\maplist.h(18) : see declaration of 'mapList'
1>c:\castle\maplist.h(54): error C2065: 'spot' : undeclared identifier
1>c:\castle\maplist.h(54): error C2275: 'mapSquares' : illegal use of this type as an expression
1>          c:\castle\mapsquares.h(5) : see declaration of 'mapSquares'
1>c:\castle\maplist.h(54): error C2146: syntax error : missing ')' before identifier 'toAdd'
1>c:\castle\maplist.h(54): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\castle\maplist.h(54): error C2078: too many initializers
1>c:\castle\maplist.h(54): error C2275: 'mapSquares' : illegal use of this type as an expression
1>          c:\castle\mapsquares.h(5) : see declaration of 'mapSquares'
1>c:\castle\maplist.h(54): error C2059: syntax error : ')'
1>c:\castle\maplist.h(55): error C2143: syntax error : missing ';' before '{'
1>c:\castle\maplist.h(55): error C2447: '{' : missing function header (old-style formal list?)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


Thanks for any help you can offer.
You need to define your member functions within your class (struct in this case.) You also need a constructor. That should help get rid of a lot of errors.
Can we see mapSquares.h?
mapSquares
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#ifndef MAPSQUARES_H
#define MAPSQUARES_H

class mapSquares
{
private:
	int xLocat;
	int yLocat;

public:
	mapSquares(){xLocat=0;yLocat=0;}
	mapSquares(int xSet, int ySet)
	{
		xLocat=xSet;
		yLocat=ySet;
	}


}



#endif 


@Kooth I'm still pretty new, I don't understand what you mean.

I was copying this version of something I did earlier, and this worked

LIST
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
#ifndef LIST_H
#define LIST_H


#include "baseUnit.h"

struct list
{
	baseUnit data;
	list *next;
};

list* insert(list * &head, baseUnit toAdd)
{
	list *newList;

	newList = new list;

	newList->data = toAdd;

	newList->next = head;
	head= newList;
	return head;
}

#endif 
Do you notice how mapSquares has two constructors? You need at least one for mapList. You need to define insertN() within your struct, etc.
okay. Why is that different from the LIST.H that I can compile and run. baseUnit has more than two constructors as well.
Look at line 19 of mapSquares.h
1>c:\castle\maplist.h(9): error C2236: unexpected 'struct' 'mapList'. Did you forget a ';'?
Last edited on
Ah dang...

Still trying to get used to C++ from JAVA. I didn't expect the error to be outside of mapList, but thanks for catching me on that.
Even though I started with C++ before any other language I still make that mistake sometimes, it's common because it's one of the only places you need to put a semicolon after the scope end brace.
Good eye, LB. Sometimes I can't see the forest for the trees. This was one of those times. Sorry for the run-around.
Last edited on
Topic archived. No new replies allowed.