Class of classes does not compile, 30+ errors

I cannot understand why this does not compile. I used these exact(obviously not exact as it doesn't compile anymore) these header files succesfully, tried them out in main(). I tried to write another function to my functions.cpp(contains all other functions except main()) and when trying to test with the new function i got over 30 errors, all in Class_Player.h. The header file Class_Pokemon.h SHOULD be functioning as i've tested it in many ways and not changed anything since. Even without new function completely deleted it fails to compile. Comments on any bad habits i may have are greatly appreciated and taken only as constructive criticism, however harsh :).
P.S simple answers please, i didnt know what programming was until 2 months ago.

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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#include "stdafx.h"
#include "Class_Pokemon.h"
#include "Misc_header.h"
class Player
{
	public:
		Pokemon m_cVenusaur;
		Pokemon m_cBlastoise;
		Pokemon m_cBlaziken;
		Player(name eName, name eName2, name eName3)
			: m_cVenusaur(eName), m_cBlastoise(eName2), m_cBlaziken(eName3)
		{
		}
};
#endif

#pragma once
#ifndef CLASS_POKEMON_H
#define CLASS_POKEMON_H
#include <cstdlib>
#include "stdafx.h"
#include "Misc_header.h"


class Pokemon
{
	friend void BattleTurn(Pokemon &X, Pokemon &Y);
private:
	int m_nHP;
	int m_nSpeed;
	int m_nAttack;
	int m_nDefense;
	type m_eType;
	name m_eName;
	bool m_bActive;
public:	
	Pokemon(name eName)
		{
			switch (eName)
		{
		case VENUSAUR:
			m_nHP = 300;
			m_nSpeed = 80;
			m_nAttack = 82;
			m_nDefense = 83;
			m_eType = GRASS;
			m_eName = eName;
			break;
		case BLAZIKEN:
			m_nHP = 300;
			m_nSpeed = 100;
			m_nAttack = 120;
			m_nDefense = 70;
			m_eType = GRASS;
			m_eName = eName;
			break;
		case BLASTOISE:
			m_nHP = 300;
			m_nSpeed = 78;
			m_nAttack = 83;
			m_nDefense = 100;
			m_eType = GRASS;
			m_eName = eName;
			break;
		default: exit(0);
		}
			m_bActive = false;
		}
	Pokemon()
	{
		int m_nHP = 0;
		int m_nSpeed = 0;
		int m_nAttack = 0;
		int m_nDefense = 0;
		type m_eType = CUNT;
	}
	int GetHP() { return m_nHP; }
	int GetSpeed() { return m_nSpeed; }
	int GetAttack() { return m_nAttack; }
	int GetDefense() { return m_nDefense; }
	int GetType() { return m_eType; }
	bool GetIsActive() { return m_bActive; }
};
#endif

#pragma once
#ifndef MISC_HEADER_H
#define MISC_HEADER_H
#include "stdafx.h"
#include "Class_Pokemon.h"
#include "Class_Player.h"

unsigned int generate(int nMax);
enum move
{
	NONE, // 0
	FLAMETHROWER = 95, // 1
	SURF = 96, // 2
	PETALDANCE = 70, // 3
	FIREBLAST = 120, // 4
	HYDROPUMP = 121, // 5
	FRENZYPLANT = 150, // 6
	HYPERBEAM = 151, // 7
	SLASH = 95, // 8
};
enum name
{
	SHIT, // 0
	VENUSAUR,
	BLAZIKEN,
	BLASTOISE,
};
enum type
{
	NILL, // 0
	GRASS, 
	FIRE, 
	WATER,
	GROUND,
	FLYING,
	NORMAL,
	DRAGON,
};
#endif 
What exactly those errors are?
Last edited on
Only error I see is that the enum value on line 75 is not defined.
was mad when i wrote the enum @ 75, changed it to nill in the declaration when copy pasting onto forum because it was embarassing :3, must have missed the top one. So that cant be the error...
1>------ Build started: Project: pokemon, Configuration: Debug Win32 ------
1> pokemon.cpp
1>c:\users\johan\documents\visual studio 2010\projects\pokemon\pokemon\class_player.h(10): error C2146: syntax error : missing ';' before identifier 'm_cVenusaur'
1>c:\users\johan\documents\visual studio 2010\projects\pokemon\pokemon\class_player.h(10): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\johan\documents\visual studio 2010\projects\pokemon\pokemon\class_player.h(10): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\johan\documents\visual studio 2010\projects\pokemon\pokemon\class_player.h(11): error C2146: syntax error : missing ';' before identifier 'm_cBlastoise'
1>c:\users\johan\documents\visual studio 2010\projects\pokemon\pokemon\class_player.h(11): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\johan\documents\visual studio 2010\projects\pokemon\pokemon\class_player.h(11): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\johan\documents\visual studio 2010\projects\pokemon\pokemon\class_player.h(12): error C2146: syntax error : missing ';' before identifier 'm_cBlaziken'
1>c:\users\johan\documents\visual studio 2010\projects\pokemon\pokemon\class_player.h(12): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\johan\documents\visual studio 2010\projects\pokemon\pokemon\class_player.h(12): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\johan\documents\visual studio 2010\projects\pokemon\pokemon\class_player.h(13): error C2061: syntax error : identifier 'name'
1>c:\users\johan\documents\visual studio 2010\projects\pokemon\pokemon\class_player.h(13): error C2065: 'eName' : undeclared identifier
1>c:\users\johan\documents\visual studio 2010\projects\pokemon\pokemon\class_player.h(13): error C2065: 'eName2' : undeclared identifier
1>c:\users\johan\documents\visual studio 2010\projects\pokemon\pokemon\class_player.h(13): error C2065: 'eName3' : undeclared identifier
1>c:\users\johan\documents\visual studio 2010\projects\pokemon\pokemon\class_player.h(15): error C2614: 'Player' : illegal member initialization: 'm_cBlaziken' is not a base or member
1>c:\users\johan\documents\visual studio 2010\projects\pokemon\pokemon\class_player.h(15): error C2614: 'Player' : illegal member initialization: 'm_cBlastoise' is not a base or member
1>c:\users\johan\documents\visual studio 2010\projects\pokemon\pokemon\class_player.h(15): error C2614: 'Player' : illegal member initialization: 'm_cVenusaur' is not a base or member
1> Functions_pokemon.cpp
1>c:\users\johan\documents\visual studio 2010\projects\pokemon\pokemon\class_player.h(10): error C2146: syntax error : missing ';' before identifier 'm_cVenusaur'
1>c:\users\johan\documents\visual studio 2010\projects\pokemon\pokemon\class_player.h(10): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\johan\documents\visual studio 2010\projects\pokemon\pokemon\class_player.h(10): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\johan\documents\visual studio 2010\projects\pokemon\pokemon\class_player.h(11): error C2146: syntax error : missing ';' before identifier 'm_cBlastoise'
1>c:\users\johan\documents\visual studio 2010\projects\pokemon\pokemon\class_player.h(11): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\johan\documents\visual studio 2010\projects\pokemon\pokemon\class_player.h(11): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\johan\documents\visual studio 2010\projects\pokemon\pokemon\class_player.h(12): error C2146: syntax error : missing ';' before identifier 'm_cBlaziken'
1>c:\users\johan\documents\visual studio 2010\projects\pokemon\pokemon\class_player.h(12): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\johan\documents\visual studio 2010\projects\pokemon\pokemon\class_player.h(12): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\johan\documents\visual studio 2010\projects\pokemon\pokemon\class_player.h(13): error C2061: syntax error : identifier 'name'
1>c:\users\johan\documents\visual studio 2010\projects\pokemon\pokemon\class_player.h(13): error C2065: 'eName' : undeclared identifier
1>c:\users\johan\documents\visual studio 2010\projects\pokemon\pokemon\class_player.h(13): error C2065: 'eName2' : undeclared identifier
1>c:\users\johan\documents\visual studio 2010\projects\pokemon\pokemon\class_player.h(13): error C2065: 'eName3' : undeclared identifier
1>c:\users\johan\documents\visual studio 2010\projects\pokemon\pokemon\class_player.h(15): error C2614: 'Player' : illegal member initialization: 'm_cBlaziken' is not a base or member
1>c:\users\johan\documents\visual studio 2010\projects\pokemon\pokemon\class_player.h(15): error C2614: 'Player' : illegal member initialization: 'm_cBlastoise' is not a base or member
1>c:\users\johan\documents\visual studio 2010\projects\pokemon\pokemon\class_player.h(15): error C2614: 'Player' : illegal member initialization: 'm_cVenusaur' is not a base or member
1> Generating Code...
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========



its as if the '#include's are not working...
You have circular includes. Remove the includes of player.h and pokemon.h from misc.h (lines 90-91). There is no reason that misc.h needs the declarations for Pokemon or Player.

In addition to the undefined enum value at line 75 I mentioned before, you also have an extraneous #endif at line 15.
Last edited on
HE has header guards, so it is not a problem.

EDIT: I was wrong, it would. However precompiled headers problem still can bite him.

you also have an extraneous #endif at line 15.
I believe corresponding header guard part was not copied


I googled and found out that it is a Visual Studio problem.
First of all you should not include precompiled headers (#include "stdafx.h" ) in header files.

However #include "stdafx.h" should be first line in every cpp file. Because anything before it will not compile: http://stackoverflow.com/a/16040842/3410396
Last edited on
Actually, player.h (as posted) does not have inclusion guards although there is an extraneous #endif indicating there might have been an inclusion guard that wasn't copy/pasted correctly.

I stand by my comment to remove lines 90-91. The order of inclusion is critical. If misc.h is included first, it will include pokemon.h and player.h before the enums in misc.h have been processed thereby forcing errors. The OP hasn't posted his .cpp files, so we can't be sure of the order of inclusion of his header files.
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
enum move
{
	NONE, // 0
	FLAMETHROWER = 95, // 1
	SURF = 96, // 2
	PETALDANCE = 70, // 3
	FIREBLAST = 120, // 4
	HYDROPUMP = 121, // 5
	FRENZYPLANT = 150, // 6
	HYPERBEAM = 151, // 7
	SLASH = 95, // 8
};
enum name
{
	SHIT, // 0
	VENUSAUR,
	BLAZIKEN,
	BLASTOISE,
};
enum type
{
	NILL, // 0
	GRASS, 
	FIRE, 
	WATER,
	GROUND,
	FLYING,
	NORMAL,
	DRAGON,
};


You have commas at the last element of every one of these
You have commas at the last element of every one of these
Allowed in C++11 (and encouraged by many)
how is that lazy? i do it. if i want to add more to it later then i already have the comma
Lines 90-91 removed and solution compiled! I would never have spotted the error myself so thanks a lot, this forum is truly amazing!
Topic archived. No new replies allowed.