Weird Errors

Hello, I am writing an evolution simulator, but I recently came across a lot of error codes. The problem is that I don't even know what is wrong in my code. I have tried every thing and this is my last solution, else I might just abandon the project.
(I will upload the whole project to GitHub, user AmazingBKaiser and probably name it Creepie Crawlers, https://github.com/AmazingBKaiser/Creepie-Crawlers.git)


I got 20 errors so it would take too long to write the all down, but to summarize most of them were telling that the variable WorldTile was not defined (crawler.h l.19) or that Crawler wasn't a valid constructor (world.h l.23)

World.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
  #pragma once
#include <PopSickles\SpriteBatch.h>
#include "Crawler.h"
#include "WorldTile.h"

class World
{
public:
	World();
	~World();

	void init(float width, float height, int xTiles, int yTiles);
	void draw(PopSickles::SpriteBatch* spriteBatch);
	void update();

	WorldTile getWorldTileOn(glm::vec2 pos);

	std::vector<WorldTile> getWorldTiles() {
		return m_worldTiles;
	}

private:
	std::vector<Crawler> m_crawlers;
	std::vector<WorldTile> m_worldTiles;

	float m_width, m_height;

	float m_timer = 0;
};


World.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
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
#include "World.h"
#include <ctime>
#include <random>

const int UPDATE_TIME = 30 * 5;

World::World()
{
}


World::~World()
{
}


void World::init(float width, float height, int xTiles, int yTiles) {
//	m_width = width;
//	m_height = height;
//
//	WorldTile worldTile;
//	worldTile.height = m_height / yTiles;
//	worldTile.width = m_width / xTiles;
//	worldTile.molekules = MolekuleList(10);
//
//	std::mt19937 generator;
//	std::uniform_real_distribution<float> xCurrent(0.001f, 1.0f);
//	std::uniform_real_distribution<float> yCurrent(0.001f, 1.0f);
//	std::uniform_real_distribution<float> lux(0.0f, 30.0f);
//	std::uniform_real_distribution<float> temperatur(15.0f, 40.0f);
//
//
//	for (int y = 0; y < yTiles; y++) {
//		for (int x = 0; x < xTiles; x++) {
//			worldTile.current.x = xCurrent(generator);
//			worldTile.current.y = yCurrent(generator);
//			worldTile.lux = lux(generator);
//			worldTile.Temperatur = temperatur(generator);
//			worldTile.pos.x = 0;//(xTiles % x + 1) * width;
//			worldTile.pos.y = 0;//(yTiles % y + 1) * width;
//			m_worldTiles.push_back(worldTile);
//
//		}
//	}
//
//	Crawler test("Pedric");
//	test.setDNA(FileManager::readDNAFile(test.getName()));
//	test.init(glm::vec2(0.0f, 0.0f));
//	m_crawlers.push_back(test);
//	m_crawlers[0].setEnergy(0.5f);
}
//
//
void World::draw(PopSickles::SpriteBatch* spriteBatch) {
//	for (auto& crawler : m_crawlers) {
//		if (crawler.isAlive()) {
//			crawler.draw(spriteBatch);
//		}
//	}
}


void World::update() {
	/*if (m_timer == 0) {
		m_timer = UPDATE_TIME;
		for (int i = 0; i < m_crawlers.size(); i++) {
			if (m_crawlers[i].isAlive()) {
				WorldTile tmp = getWorldTileOn(m_crawlers[i].getPos());
				m_crawlers[i].live(&tmp);
				if (m_crawlers[i].getBaby()->getName() != "TMP_BABY") {
					m_crawlers.push_back(*m_crawlers[i].getBaby());
					m_crawlers[i].getBaby()->getName() = "TMP_BABY";
				}
			}
		}
	}
	else {
		m_timer--;
	}*/
}

WorldTile World::getWorldTileOn(glm::vec2 pos) {
	/*for (int i = 0; i < m_worldTiles.size(); i++) {
		if (pos.x > m_worldTiles[i].pos.x && pos.y > m_worldTiles[i].pos.y && pos.x < m_worldTiles[i].pos.x + m_worldTiles[i].width && pos.y < m_worldTiles[i].pos.y + m_worldTiles[i].height) {
			return m_worldTiles[i];
		}
	}*/
}

(I commented out most of the code just to see if the bug was there. It did decrease the number of error messages, but the error is probably not in World.cpp)

Crawler.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#pragma once
#include <PopSickles/SpriteBatch.h>
#include "DNA.h"
#include "MolekuleList.h"
#include "World.h"


class Crawler
{
public:
	Crawler(std::string name);
	Crawler(std::string name, DNA& dna);
	~Crawler();

	void init(glm::vec2 pos);

	void draw(PopSickles::SpriteBatch* spriteBatch);

	void live(WorldTile* worldTile);

	void setDNA(DNA& dna);

	void setDecodedDNA(DecodedDNA decodedDNA);


	std::string& getName() {
		return _name;
	}
	DNA& getDNA() {
		return _dna;
	}

	DecodedDNA& getDecodedDNA() {
		return m_decodedDNA;
	}

	float getMutationRate(){
		return m_mutationRate;
	}

	float& getEnergy() {
		return _energy;
	}

	void setEnergy(float energy) {
		_energy = energy;
	}

	glm::vec2& getPos() {
		return m_pos;
	}

	Crawler* getBaby() {
		return m_b;
	}


	std::vector<std::pair<int, int>> getLayers() {
		return m_layers;
	}

	bool& isAlive() {
		return m_isAlive;
	}


private:
	void updateEnergy(float Temperatur, float lux);

	void initMutationRate();
	void initLayers();

	DNA MutateDNA();

	void updateInputs(int chromosomeNum);

	void calculateOutputs();

	void doOutputs(int chromosomeNum);

	void Reproduce(glm::vec2 pos);

	void drift(glm::vec2 current);

	float m_mutationRate = 0;
	DNA _dna;
	DecodedDNA m_decodedDNA;
	int _num;
	float _inputs [8];
	float _outputs [5][8];
	std::string _name;
	//current usable energy of crawler
	float _energy = 0;
	//current Temperatur and light energy absorbed by crawler
	float _TLEnergy;
	//Temperatur and light energy absorbed by crawler last frame
	float _formerTLEnergy;

	std::vector<std::pair<int, int>> m_layers;
	glm::vec2 m_pos = glm::vec2(0.0f);

	PopSickles::ColorRGBA8 m_color = COLORRGBA8_WHITE;

	Crawler* m_b = nullptr;

	bool m_isAlive = true;

	WorldTile* m_currentTile = nullptr;
};

(left out Crawler.cpp because it was too long)

Thanks in advance.
Last edited on
I got 20 errors so it would take too long to write the all down

You couldn't cut and paste from the compiler output window?
Because you didn't supply all the code, I can't compile it to duplicate your errors.

most of them were telling that the variable WorldTile was not defined (crawler.h l.19)

So where is WorldTile declared? You haven't posted a header declaring it.



Sorry my bad.
here is the complete Error list.
Warnung C4244 "Argument": Konvertierung von "float" in "unsigned int", möglicher Datenverlust Creepie Crawlers d:\projects\games\creepie crawlers\creepie crawlers\crawler.cpp 428
Fehler C2065 "Crawler": nichtdeklarierter Bezeichner Creepie Crawlers d:\projects\games\creepie crawlers\creepie crawlers\world.h 23
Fehler C2065 "Crawler": nichtdeklarierter Bezeichner Creepie Crawlers d:\projects\games\creepie crawlers\creepie crawlers\world.h 23
Fehler C2065 "Crawler": nichtdeklarierter Bezeichner Creepie Crawlers d:\projects\games\creepie crawlers\creepie crawlers\world.h 23
Fehler C2065 "Crawler": nichtdeklarierter Bezeichner Creepie Crawlers d:\projects\games\creepie crawlers\creepie crawlers\world.h 23
Fehler C2065 "Crawler": nichtdeklarierter Bezeichner Creepie Crawlers d:\projects\games\creepie crawlers\creepie crawlers\world.h 23
Fehler C2065 "Crawler": nichtdeklarierter Bezeichner Creepie Crawlers d:\projects\games\creepie crawlers\creepie crawlers\world.h 23
Fehler C2923 "std::vector": "Crawler" ist kein gültiges template-Typargument für den _Ty-Parameter. Creepie Crawlers d:\projects\games\creepie crawlers\creepie crawlers\world.h 23
Fehler C2923 "std::vector": "Crawler" ist kein gültiges template-Typargument für den _Ty-Parameter. Creepie Crawlers d:\projects\games\creepie crawlers\creepie crawlers\world.h 23
Fehler C2923 "std::vector": "Crawler" ist kein gültiges template-Typargument für den _Ty-Parameter. Creepie Crawlers d:\projects\games\creepie crawlers\creepie crawlers\world.h 23
Fehler C2923 "std::vector": "Crawler" ist kein gültiges template-Typargument für den _Ty-Parameter. Creepie Crawlers d:\projects\games\creepie crawlers\creepie crawlers\world.h 23
Fehler C2923 "std::vector": "Crawler" ist kein gültiges template-Typargument für den _Ty-Parameter. Creepie Crawlers d:\projects\games\creepie crawlers\creepie crawlers\world.h 23
Fehler C2923 "std::vector": "Crawler" ist kein gültiges template-Typargument für den _Ty-Parameter. Creepie Crawlers d:\projects\games\creepie crawlers\creepie crawlers\world.h 23
Warnung C4275 class "std::exception" ist keine DLL-Schnittstelle und wurde als Basisklasse für die DLL-Schnittstelle class "CEGUI::Exception" verwendet Creepie Crawlers d:\projects\games\creepie crawlers\deps\include\cegui\exceptions.h 41
Warnung C4275 class "std::exception" ist keine DLL-Schnittstelle und wurde als Basisklasse für die DLL-Schnittstelle class "CEGUI::Exception" verwendet Creepie Crawlers d:\projects\games\creepie crawlers\deps\include\cegui\exceptions.h 41
Warnung C4275 class "std::exception" ist keine DLL-Schnittstelle und wurde als Basisklasse für die DLL-Schnittstelle class "CEGUI::Exception" verwendet Creepie Crawlers d:\projects\games\creepie crawlers\deps\include\cegui\exceptions.h 41
Warnung C4275 class "std::exception" ist keine DLL-Schnittstelle und wurde als Basisklasse für die DLL-Schnittstelle class "CEGUI::Exception" verwendet Creepie Crawlers d:\projects\games\creepie crawlers\deps\include\cegui\exceptions.h 41
Fehler C4430 Fehlender Typspezifizierer - int wird angenommen. Hinweis: "default-int" wird von C++ nicht unterstützt. Creepie Crawlers d:\projects\games\creepie crawlers\creepie crawlers\crawler.h 108
Fehler C4430 Fehlender Typspezifizierer - int wird angenommen. Hinweis: "default-int" wird von C++ nicht unterstützt. Creepie Crawlers d:\projects\games\creepie crawlers\creepie crawlers\crawler.h 108
Fehler C2061 Syntaxfehler: Bezeichner "WorldTile" Creepie Crawlers d:\projects\games\creepie crawlers\creepie crawlers\crawler.h 19
Fehler C2061 Syntaxfehler: Bezeichner "WorldTile" Creepie Crawlers d:\projects\games\creepie crawlers\creepie crawlers\crawler.h 19
Fehler C2143 Syntaxfehler: Es fehlt ";" vor "*" Creepie Crawlers d:\projects\games\creepie crawlers\creepie crawlers\crawler.h 108
Fehler C2143 Syntaxfehler: Es fehlt ";" vor "*" Creepie Crawlers d:\projects\games\creepie crawlers\creepie crawlers\crawler.h 108
Fehler C2238 Unerwartete(s) Token vor ";" Creepie Crawlers d:\projects\games\creepie crawlers\creepie crawlers\crawler.h 108
Fehler C2238 Unerwartete(s) Token vor ";" Creepie Crawlers d:\projects\games\creepie crawlers\creepie crawlers\crawler.h 108
(it is in german).

Here is WorldTile.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#pragma once
#include "MolekuleList.h"
#include <glm/glm.hpp>

struct WorldTile {
	WorldTile(float Width, float Height, float Temp, float Lux, glm::vec2 Current, MolekuleList Molekules) : width(Width), height(Height), Temperatur(Temp), lux(Lux), current(Current), molekules(Molekules) {

	}
	WorldTile() {

	}

	float width, height;
	float Temperatur, lux;
	glm::vec2 current;
	MolekuleList molekules;
	glm::vec2 pos;
};


It doesn't have a cpp file.
My German is rusty, but most of those errors are pretty obvious.

world.h line 23: Crawler is undefined. I do see that world.h includes crawler.h. Looking crawler.h line 5, you include world.h. This is a classic case of recursive includes. i.e. a.h includes b.h. b.h includes a.h.

Recursive defines should be avoided. Often creating recursive defines is just an oversight when not enough thought has been given to the class hierarchy.

However, there are cases where the are legitimate reasons for class A to reference class B and for class B to reference class A. If this is the case, the easiest way around this is to use a forward declaration for one of the classes. This means in the header (A) that has the forward declaration for B, B can only be passed by reference or as a pointer. It can not be passed by value since the compiler does not the size of B when it is declared forward.
Thanks very much. I would never have thought that the errors came from a case of recursive includes.
Thanks
Topic archived. No new replies allowed.