weird error with 4-way binary tree

I am just getting a weird list of errors and any help at all would be greatly appreciated.

HERE:


1>------ Build started: Project: chunksaveing, Configuration: Debug Win32 ------
1> BinaryTree.cpp
1>c:\users\jason\documents\visual studio 2012\projects\chunksaveing\chunksaveing\binarytree.cpp(57): warning C4715: 'tree::search' : not all control paths return a value
1> main.cpp
1>main.obj : error LNK2005: "void __cdecl genTerrain(class chunks)" (?genTerrain@@YAXVchunks@@@Z) already defined in BinaryTree.obj
1>main.obj : error LNK2005: "public: void __thiscall chunks::start(void)" (?start@chunks@@QAEXXZ) already defined in BinaryTree.obj
1>BinaryTree.obj : error LNK2019: unresolved external symbol "public: void __thiscall chunks::searchArea(void)" (?searchArea@chunks@@QAEXXZ) referenced in function "public: void __thiscall chunks::start(void)" (?start@chunks@@QAEXXZ)
1>main.obj : error LNK2001: unresolved external symbol "public: void __thiscall chunks::searchArea(void)" (?searchArea@chunks@@QAEXXZ)
1>C:\Users\Jason\Documents\Visual Studio 2012\Projects\chunksaveing\Debug\chunksaveing.exe : fatal error LNK1120: 1 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========



that is the error and here is my code:


main.cpp:

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

#include <iostream>
#include "Chunks.h"
#include "BinaryTree.h"



using namespace std;

int main(int argc, int argv[])
{
	tree root;
	node *leaf;
	node *test;
	loc key;
	
	key.corner = 1;
	key.mBranch = 2;
	key.sBranch = 2;
	key.leaf = true;
	
	leaf = new node;
	leaf->key.corner = 1;
	leaf->key.mBranch = 0;
	leaf->key.sBranch = 0;
	leaf->key.leaf = false;
	
	test = root.search(key, leaf);
	test->world.create = true;
	test->world.start();
	genTerrain(test->world);
	
	for(int a = 0; a > 10; a++)
		for(int b = 0; b > 10; b++){
			cout << test->world.chunk[a][b]->id;
			if(a = 9)
				cout << "/n";
		}
	system("PAUSE");
	return(0);
}



BinaryTree.cpp:

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

#include "BinaryTree.h"

node *tree::search(loc key, node * leaf){
	if(key.corner == leaf->key.corner && key.mBranch == leaf->key.mBranch && key.sBranch == leaf->key.sBranch){
		if(key.leaf = false){
		return(leaf);
		}
		else if(leaf->right == NULL && key.leaf == true){
			leaf->right = new node;
			leaf->right->key.leaf = true;
			leaf->right->key.sBranch = leaf->key.sBranch;
			leaf->right->key.mBranch = leaf->key.mBranch;
			branch = leaf->right;
			return(branch);
		}
		else if(key.leaf = true){
			branch = leaf->right;
			return(branch);
		}
	}

	if(key.corner == leaf->key.corner && key.mBranch == leaf->key.mBranch && key.sBranch > leaf->key.sBranch){
		if(leaf->right == NULL){
			leaf->right = new node;
			leaf->right->key.leaf = false;
			leaf->right->key.sBranch = leaf->key.sBranch+1;
			leaf->right->key.mBranch = leaf->key.mBranch;
		}
		branch = search(key, leaf->right);
		return(branch);
	}

	if(key.corner == leaf->key.corner && key.mBranch > leaf->key.mBranch){
		if(leaf->left = NULL){
			leaf->left = new node;
			leaf->left->key.leaf = false;
			leaf->left->key.mBranch = leaf->key.mBranch + 1;
			leaf->left->key.sBranch = leaf->key.sBranch;
		}
		branch = search(key, leaf->left);
		return(branch);
	}

	if(key.corner != leaf->key.corner){
		if(leaf->key.corner == NULL){
			leaf->key.corner = 0;
			branch = search(key, leaf);
			return(branch);
		}
		else if(key.corner > leaf->key.corner){
			branch->key.corner = leaf->key.corner + 1;
			branch = search(key, branch);
			return(branch);
		}
	}
}



BinaryTree.h:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#ifndef BinaryTree_h
#define BinaryTree_h

#include "Chunks.h"

class node{
public:
	loc key;// main location of the node
	node *left;//branch of the node
	node *right;// branch or leaf fo the node
	chunks world;//the actual chunk of the world for this node
};

class tree{
public:
	node *search(loc key, node *leaf);//contains the search algorithm
	void save(loc key, node *leaf);//contains the save algorithm
	void destroy(loc key, node *leaf);//destorys a specific node
	node *branch;
};


#endif 


Chunks.h:

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
#include <stdlib.h>

#ifndef Chunks_h
#define Chunks_h

#include "locationStat.h"


class block{
public:
	int id;//identification number of the block which is used to determin block stats
};

class area{
public:
	loc *ch1x1;
	loc *ch1x2;
	loc *ch1x3;
	loc *ch1x4;
	loc *ch2x1;
	loc *ch2x2;
	loc *ch2x3;
	loc *ch2x4;
	loc *ch3x1;
	loc *ch3x2;
	loc *ch3x3;
	loc *ch3x4;
	loc *ch4x1;
	loc *ch4x2;
	loc *ch4x3;
	loc *ch4x4;
};

class chunks{
public:
	block *chunk[1][1];
	area surroundingChunks; //the area around the chunk 4x4
	void searchArea(); //used to find the immediate area around the chunk.
	bool create; //determins if the chunk is to be generated or just left as bool
	void start(); //checks the state of create, runs chunk area, and generates terrain from a class 
};



void chunks::start(){
	if(create == true){
		chunk[0][0] = new block[10], new block[10];
		searchArea();
	}

	if(create != true){
		searchArea();
	}
}

void genTerrain(chunks chunk){
	for(int a = 0; a < 10; a++)
		for(int b = 0; b < 10; b++)
			chunk.chunk[a][b]->id = rand() % 4;
}






#endif 


locationStats.h:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#ifndef locationStat_h 
#define locationStat_h

class loc{
public:
	int corner;//contains which of the 4 corners this node occupies
	int mBranch;//main branch of the node
	int sBranch;//a single branch on a specific area of the main branch
	bool leaf;//a part of the sub-branch at a specific point
};



#endif 




Now there are a few things in the code that are not coded yet just so you know.
Last edited on
Try putting Header Guards on your header files first.
Last edited on
Don't include .cpp files in other .cpp files (unless you know what you're doing).
I updated the code and the error. its generally the same thing but i still can't figure out what is causing the weird error.
main.cpp still includes BinaryTree.cpp.
As helios said, you cant do this in main.cpp:
1
2
3
4
5
6
7
8
9
#include <iostream>
#include "BinaryTree.cpp"



using namespace std;

int main(int argc, int argv[])
{


Change it to this like in chunks.cpp:
1
2
3
4
5
6
7
8
9
#include <iostream>
#include "Chunks.h"



using namespace std;

int main(int argc, int argv[])
{


2 more things...
1) Some compilers complain if you have system includes inside of the Header Guard.
2) You dont need to actually define the Header Guard as some value, just defining it (asserting its presence) is good enough.
Change this in Chunks.h:
1
2
3
4
5
6
7
#ifndef Chunks_h
#define Chunks_h 0

#include <stdlib.h>
#include "locationStat.h"

class block{


To this:
1
2
3
4
5
6
7
8
#include <stdlib.h>

#ifndef Chunks_h
#define Chunks_h

#include "locationStat.h"

class block{

Also get rid of the Guards in the .cpp files, they don't do anything for you in a .cpp file - because you shouldn't include a .cpp file.
1) Some compilers complain if you have system includes inside of the Header Guard.
Huh?
Huh?

I got what he meant.


Ok i updated the code again here and in the program and i'm still getting the error...idk what could be the problem. This is really starting to irritate me.
Last edited on
I got what he meant.
Okay, but it's false. It's perfectly legal to use any preprocessor directive inside an inclusion guard.

You're defining chunks::start() and genTerrain() in a header. Move the definitions to a .cpp file.
Yeah, it is legal. And in any logical argument there should be no problem doing so.

I think it is only a compiler warning, I just recall coming in to the habit of putting them before the guards to avoid one (I am willing to bet it is one of the MS compilers that generates it.) I really do hate compiler warnings, and I regularly use 5 different C++ compilers (VS6 - yeah, VS2008, VS2010, VS2012, and GNU C++) at work and counting personal projects.
Last edited on
I've never come across any warning like that, and I've used each of the compilers in that list. It just doesn't make sense for any compiler to throw a warning over something like that. It's merely an application of conditional compilation.
Topic archived. No new replies allowed.